<@U04UQ68083H> Can I add a second authentication m...
# ory-copilot
p
@chilly-king-10285 Can I add a second authentication method to an identity? And if so, which API endpoint do I use?
c
A message from kapa.ai
Yes, you can add a second authentication method to an identity using Ory's step-up authentication feature. This feature allows you to protect sensitive functions of your application by making users complete a second authentication factor in their current session. To initiate a new login flow with a second authentication factor, you can use one of the following endpoints with the
aal
parameter set to `aal2`: -
/self-service/login/browser
-
/self-service/login/api
For example:
Copy code
/self-service/login/browser?aal=aal2   /self-service/login/api?aal=aal2
If the Ory Session already has
aal2
, this will result in an error. In that case, you can request to refresh the session using the second factor:
Copy code
/self-service/login/browser?refresh=true&aal=aal2   /self-service/login/api?refresh=true&aal=aal2
When the user successfully provides their configured second factor, the method (for example
totp
) is added to the Ory Session, the Ory Session Authenticator Assurance Level (AAL) is set to
aal2
, and the
authenticated_at
time is set to the time when the user provides the second factor. Please note that to perform this operation, you must be authenticated by means of the
oryAccessToken
method. For more details, please refer to the [Ory documentation](https://www.ory.sh/docs/kratos/mfa/step-up-authentication#trigger-dynamic-multi-factor-authentication).
p
@chilly-king-10285 I do not mean two auth methods to login. I mean a user can login via OIDC or password. Is this possible?
c
A message from kapa.ai
Yes, it is possible for a user to log in using either OIDC or a password in Ory. These are considered as first authentication factors. You can configure which methods to use in the Ory Identities configuration or in the Console UI. Here is an example of how to enable both password and OIDC methods in the configuration:
Copy code
yaml selfservice:     methods:       password:         enabled: true       oidc:         enabled: true     # ...
For OIDC, Ory supports a variety of providers including GitHub, Apple, GitLab, Google, Facebook, and any other OpenID Connect Certified Provider. Please note that using two first authentication factors (like
password
and
oidc
) doesn't give the user
aal2
(Authenticator Assurance Level 2).
aal2
is achieved when the user completes both the first and the second authentication factor(s). For more details, please refer to the [Ory documentation](https://www.ory.sh/docs/kratos/self-service/flows/user-login) and [Ory MFA Overview](https://www.ory.sh/docs/kratos/mfa/overview#authenticator-assurance-level-aal).
p
@chilly-king-10285 which ory API endpoint do I use to add the second method to an existing identity?
c
A message from kapa.ai
I'm sorry for any confusion, but based on the provided knowledge sources, there isn't a specific API endpoint mentioned for adding a second authentication method to an existing identity. The Ory Kratos system is designed to handle multiple authentication methods, but the specifics of adding a second method to an existing identity might depend on your implementation and configuration. For managing identities, Ory provides endpoints like
createIdentity
and
updateIdentity
, but these require an
oryAccessToken
for authentication and their usage isn't explicitly described in the context of adding a second authentication method in the provided sources. For more detailed information, I would recommend referring to the [Ory Kratos documentation](https://www.ory.sh/docs/kratos/) or the [Ory API reference](https://www.ory.sh/docs/reference/api).
p
@chilly-king-10285 Looks like Update Identity can add a password trait to an existing identity.
c
A message from kapa.ai
Yes, you can use the
updateIdentity
API endpoint to modify the traits of an existing identity, which could include adding a password trait. However, please note that the
updateIdentity
API overwrites the existing identity with the one provided in the request body. So, you should include all the existing traits that you want to keep in addition to the new ones you want to add. Here is an example of how you might use the
updateIdentity
API to add a password trait:
Copy code
bash curl -d "@identity-$IDENTITY_ID.json" -X PUT https://$<http://ORY_SLUG.projects.oryapis.com/admin/identities/$IDENTITY_ID|ORY_SLUG.projects.oryapis.com/admin/identities/$IDENTITY_ID> \ -H "Authorization: Bearer $ORY_API_KEY" \ -H'Content-Type: application/json'
In the
identity-$IDENTITY_ID.json
file, you would include the existing identity traits and the new password trait. However, it's important to note that the command shown does not create a password or any other type of credential for the identity. The password or other credentials would need to be handled separately, likely through a separate process involving the user. For more details, please refer to the [Ory documentation](https://www.ory.sh/docs/guides/integrate-with-ory-cloud-through-webhooks#update-identity-traits) and [Ory API reference](https://www.ory.sh/docs/reference/api#tag/identity/operation/updateIdentity).
p
@chilly-king-10285 In case anyone is following along, it looks like if an identity schema enables both password and OIDC and the user registers with OIDC, they can still add a password to their identity by following a change-password flow. Once thy do that, the user can login via OIDC or password.
c
A message from kapa.ai
Yes, you're correct. If an identity schema enables both password and OIDC, and a user registers with OIDC, they can indeed add a password to their identity by following a change-password flow. Once they do that, the user can log in via either OIDC or password. Here's how it works: 1. The user registers using OIDC. 2. The user initiates a password change flow. This can be done by making a request to the
/self-service/settings/browser
endpoint for browser-based flows or the
/self-service/settings/api
endpoint for API-based flows. 3. The user completes the password change flow by providing a new password. 4. After the password is successfully changed, the user can log in using either the OIDC method or the password method. Please note that the specifics of this process might depend on your implementation and configuration of Ory Kratos. For more details, please refer to the [Ory Kratos documentation](https://www.ory.sh/docs/kratos/self-service/flows/user-settings#changing-passwords).