# iOS CredentialsManager not retrieving with non-OIDC

**URL:** <https://community.auth0.com/t/ios-credentialsmanager-not-retrieving-with-non-oidc/7611>\
**Category:** Get Help\
**Tags:** auth0swift, swift, auth0, lock, ios\
**Created:** [July 21, 2017, 8:39am UTC](https://community.auth0.com/t/ios-credentialsmanager-not-retrieving-with-non-oidc/7611 "2017-07-21T08:39:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![david.yee](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@david.yee](https://community.auth0.com/u/david.yee)\
**Post date:** [July 21, 2017, 8:39am UTC](https://community.auth0.com/t/ios-credentialsmanager-not-retrieving-with-non-oidc/7611/1 "2017-07-21T08:39:53Z")

</div>

I am using the Lock.swift (v2.3.1) and Auth0.Swift (v1.7.1) SDKs for iOS 9+. [In the documentation for Auth0.Swift](https://github.com/auth0/Auth0.swift#credentials-management-utility-ios-only), it suggests that the class `CredentialsManager` can be used to store the `Credentials` object and retrieve it again later. This feature works correctly when I use Lock with OIDC conformance set to true. However, it does not behave as expected when OIDC conformance is set to false.

Below is a working example:

```
Lock
  .classic()
  .withConnections { (connections: inout ConnectionBuildable) in 
    connections.database(name: "Username-Password-Authentication", requiresUsername: true)
  }
  .withOptions { (options: inout OptionBuildable) in
    options.scope = "openid profile user_metadata app_metadata" // some custom scopes
    options.oidcConformant = true
  }
  .onAuth { (credentials: Credentials) in
    let credentialsManager = CredentialsManager(authentication: Auth0.authentication())
    let isCredentialsStored = self.credentialsManager.store(credentials: credentials)
    
    if isCredentialsStored {
      print("Credentials saved: \(credentials.debugDescription)")
      
      let isValid = self.credentialsManager.hasValid()
      if isValid {
        print("Valid!")
      } else {
        print("Invalid!")
      }
      
      credentialsManager.credentials { (error: CredentialsManagerError?, credentials: Credentials?) in
        if let error = error {
          print("Failed to instantly retrieve the credentials with error: \(error)")
        }
      }
    }
  }

```

Output ( `oidcConformant = true` ):

```
Credentials saved: <A0Credentials: 0x14d2a930>
Valid!

```

Output ( `oidcConformant = false` ):

```
Credentials saved: <A0Credentials: 0x15dc0a10>
Invalid!
Failed to instantly retrieve the credentials with error: noCredentials

```

Note that when `oidcConformant = false`, the variable in the above example, `isCredentialsStored`, still evaluates as true! However, the `hasValid` and `credentials` method in `CredentialsManager` both fail.

Is there a reason why the credentials manager cannot retrieve a stored credential when OIDC conformance is set to false? How can I store the `Credentials` object while using non-OIDC conformance?

---

<div class="post-metadata">

**Author:** ![jmangelo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jmangelo/32/7923_2.png) [@jmangelo](https://community.auth0.com/u/jmangelo)\
**Post date:** [July 21, 2017, 3:32pm UTC](https://community.auth0.com/t/ios-credentialsmanager-not-retrieving-with-non-oidc/7611/2 "2017-07-21T15:32:26Z")

</div>

Purely from reading the [code](https://github.com/auth0/Auth0.swift/blob/429356400aa6e9554d99f036dbede102d7d74f12/Auth0/CredentialsManager.swift#L78) (aka I did not run it to prove this theory) it seems that what triggers that situation is that in OIDC mode the response will contain an `expires_in` parameter in accordance to the specification and running Lock in non-OIDC mode will call a different endpoint that does return the previously mentioned parameter.

The above will then mean that the `hasValid` and `credentials` calls behave like that because they can’t ensure that the credentials are valid, due to lack of expiration information, and as such return false and no credentials respectively even though there is credentials data stored.

Also from the code, you could try changing the configuration to also request refresh tokens as they are also contemplated in the logic available for `hasValid` and `credentials`, however, the recommendation is for you to use OIDC mode and as such this would be a non-issue.

---

<div class="post-metadata">

**Author:** ![walsh](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/walsh/32/7074_2.png) [@walsh](https://community.auth0.com/u/walsh)\
**Post date:** [July 21, 2017, 5:28pm UTC](https://community.auth0.com/t/ios-credentialsmanager-not-retrieving-with-non-oidc/7611/3 "2017-07-21T17:28:02Z")

</div>

This utility class is designed for use with OIDC conformance, in regards to `hasValid` the non oidc conformant credentials are most likely missing the `expiresIn` value.  
[Credentials Manager → hasValid()](https://github.com/auth0/Auth0.swift/blob/master/Auth0/CredentialsManager.swift#L76)

If you wish to use the CredentialsManager you should use OIDC Conformance, the method used to renew the token also requires this. If you wish to enable a [refresh\_token](https://auth0.com/docs/tokens/refresh-token/current) you should add the `offline_access` scope.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [March 2, 2018, 5:55am UTC](https://community.auth0.com/t/ios-credentialsmanager-not-retrieving-with-non-oidc/7611/4 "2018-03-02T05:55:32Z")

</div>


