# Get list of OTP devices of User in org.keycloak.authentication.AuthenticationFlowContext

**URL:** <https://forum.keycloak.org/t/get-list-of-otp-devices-of-user-in-org-keycloak-authentication-authenticationflowcontext/27117>\
**Category:** Extending the server\
**Tags:** authentication\
**Created:** [July 23, 2024, 9:55am UTC](https://forum.keycloak.org/t/get-list-of-otp-devices-of-user-in-org-keycloak-authentication-authenticationflowcontext/27117 "2024-07-23T09:55:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![deanmaster](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/deanmaster/32/10935_2.png) [@deanmaster](https://forum.keycloak.org/u/deanmaster)\
**Post date:** [July 23, 2024, 9:55am UTC](https://forum.keycloak.org/t/get-list-of-otp-devices-of-user-in-org-keycloak-authentication-authenticationflowcontext/27117/1 "2024-07-23T09:55:58Z")

</div>

Hello everyone,

I’m implementing a custom Conditional Authentication Factory, within my logic I would like to check if the user has OTP devices registered or not.

Does anyone know the API to get list of OTP Devices of a User?

Thanks,  
Tuan Do

---

<div class="post-metadata">

**Author:** ![embesozzi](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/embesozzi/32/12390_2.png) [@embesozzi](https://forum.keycloak.org/u/embesozzi)\
**Post date:** [July 23, 2024, 8:43pm UTC](https://forum.keycloak.org/t/get-list-of-otp-devices-of-user-in-org-keycloak-authentication-authenticationflowcontext/27117/2 "2024-07-23T20:43:03Z")

</div>

Have you checked the following?  
`{user}.credentialManager().getStoredCredentialsByTypeStream(OTPCredentialModel.TYPE)`

---

<div class="post-metadata">

**Author:** ![deanmaster](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/deanmaster/32/10935_2.png) [@deanmaster](https://forum.keycloak.org/u/deanmaster)\
**Post date:** [July 25, 2024, 9:19am UTC](https://forum.keycloak.org/t/get-list-of-otp-devices-of-user-in-org-keycloak-authentication-authenticationflowcontext/27117/3 "2024-07-25T09:19:50Z")

</div>

Thank you here is my code after searching keycloak code:

```auto
OTPCredentialProvider otpCredentialProvider = (OTPCredentialProvider)context.getSession().getProvider(CredentialProvider.class, OTPCredentialProviderFactory.PROVIDER_ID);
        return otpCredentialProvider.isConfiguredFor(context.getAuthenticationSession().getRealm(), context.getUser());

```

---

<div class="post-metadata">

**Author:** ![dasniko](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/dasniko/32/2969_2.png) [@dasniko](https://forum.keycloak.org/u/dasniko)\
**Post date:** [July 25, 2024, 10:17am UTC](https://forum.keycloak.org/t/get-list-of-otp-devices-of-user-in-org-keycloak-authentication-authenticationflowcontext/27117/4 "2024-07-25T10:17:13Z")

</div>

You initial question is ambigiously worded.  
First, you ask for “if the user has OTP devices registered or not”, then “the API to get list of OTP Devices of a User”. Also the title of your post asks for the list of OTP devices of a user.

Your resulting code solves the former, @embesozzi told you the code for the latter.  
Always make sure to formulate your questions clearly.

---

<div class="post-metadata">

**Author:** ![deanmaster](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/deanmaster/32/10935_2.png) [@deanmaster](https://forum.keycloak.org/u/deanmaster)\
**Post date:** [July 25, 2024, 10:50am UTC](https://forum.keycloak.org/t/get-list-of-otp-devices-of-user-in-org-keycloak-authentication-authenticationflowcontext/27117/5 "2024-07-25T10:50:27Z")

</div>

that’s very good point. I think during the asking I found the new APIs which I post to just tell me if User get OTP device configured or not to continue the process authentication.

Next time I will make my question more clearly and updated according to the context thank you.
