# Getting an error when loging into an SP using my own UserStorageProvider with my external database's users

**URL:** <https://forum.keycloak.org/t/getting-an-error-when-loging-into-an-sp-using-my-own-userstorageprovider-with-my-external-databases-users/20117>\
**Category:** Getting advice\
**Tags:** authentication\
**Created:** [February 8, 2023, 11:08am UTC](https://forum.keycloak.org/t/getting-an-error-when-loging-into-an-sp-using-my-own-userstorageprovider-with-my-external-databases-users/20117 "2023-02-08T11:08:42Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![A.Alonso](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/a.alonso/32/7610_2.png) [@A.Alonso](https://forum.keycloak.org/u/A.Alonso)\
**Post date:** [February 8, 2023, 11:08am UTC](https://forum.keycloak.org/t/getting-an-error-when-loging-into-an-sp-using-my-own-userstorageprovider-with-my-external-databases-users/20117/1 "2023-02-08T11:08:42Z")

</div>

I am trying to implement a User Storage Provider. Most of it is already implemented, and when I add it in the admin console UI, I can see the users in the list. I deactivated OTP and now I can log-in with my users. The problem is the next one:

When I enter the second time in my SP, it fails to do it. I think I am having a problem related to client scopes and that KeyCloak cannot use or access the mappers in those client scopes, leading to the login error in the Service Provider.

I cannot access them (the client Scopes) when I add my external SPI, which I don’t know how it interacts with client scopes. When I enter, I receive this error in my Admin Console UI (1) / KeyCloak’s Docker container log (2):

![Error message](https://global.discourse-cdn.com/free1/uploads/keycloak/original/2X/a/ae9daf28d6ed590e126fe09e88b6d87b6fa198e1.png)  
**(1)**

```auto
2023-02-08 11:47:11 ---------------------
2023-02-08 11:47:11 org.keycloak.models.cache.infinispan.RealmCacheSession@1302ca2
2023-02-08 11:47:11 2023-02-08 10:47:11,413 ERROR [org.keycloak.services.error.KeycloakErrorHandler] (executor-thread-35) Uncaught server error: com.fasterxml.jackson.databind.JsonMappingException: [no message for java.lang.NullPointerException]
2023-02-08 11:47:11 at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider._wrapAsIOE(DefaultSerializerProvider.java:509)
2023-02-08 11:47:11 at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider._serialize(DefaultSerializerProvider.java:482)
2023-02-08 11:47:11 at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:400)
2023-02-08 11:47:11 at com.fasterxml.jackson.databind.ObjectWriter$Prefetch.serialize(ObjectWriter.java:1514)
2023-02-08 11:47:11 at com.fasterxml.jackson.databind.ObjectWriter.writeValue(ObjectWriter.java:1007)
[...]

Caused by: java.lang.NullPointerException
2023-02-08 11:42:39 at org.keycloak.models.utils.ModelToRepresentation.toRepresentation(ModelToRepresentation.java:263)
2023-02-08 11:42:39 at org.keycloak.services.resources.admin.UsersResource.lambda$toRepresentation$2(UsersResource.java:459)
2023-02-08 11:42:39 at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
2023-02-08 11:42:39 at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:177)
2023-02-08 11:42:39 at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:177)
2023-02-08 11:42:39 at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
[...]

```

**(2)**

From what I can gather, the line 263 of `ModelToRepresentation.java` is in the `toRepresentation()` method of the class `UserRepresentation`, being the line the following:

`rep.setTotp(user.credentialManager().isConfiguredFor(OTPCredentialModel.TYPE));`

Also, some extra information:

```auto
KeyCloak's version: 20.0.3

Java JDK version: 11

```

Can someone lend me a hand? I am kind of lost here… Thanks a lot in advance guys, you have been really helpful these last days.
