Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a synchronous way of retrieving the currently stored Credentials #437

Closed
JanC opened this issue Dec 29, 2020 · 6 comments · Fixed by #482
Closed

Provide a synchronous way of retrieving the currently stored Credentials #437

JanC opened this issue Dec 29, 2020 · 6 comments · Fixed by #482
Labels
feature request A feature has been asked for or suggested by the community help wanted

Comments

@JanC
Copy link

JanC commented Dec 29, 2020

Describe the problem you'd like to have solved

Hey,
as a SDK user, I'd like to retrieve the currently stored Credentials in a synchronous way so that I can access some metadata stored in Credentials.idToken regardless of the credentials validity

Describe the ideal solution

In the same way Auth0.CredentialsManager provides a way to store the credentials, it could provide a sync method to retrieve them:

func credentials() -> Credentials? {
    guard let data = self.storage.data(forKey: self.storeKey),
          let credentials = NSKeyedUnarchiver.unarchiveObject(with: data) as? Credentials else {
        return nil
    }
    return credentials
}

Alternatives and current work-arounds

A workaround is to use directly the A0SimpleKeychain without relying on the Auth0.CredentialsManager and use the same storeKey as the one passed in the init of Auth0.CredentialsManager:

private extension A0SimpleKeychain {
    func credentials(_ storeKey: String) -> Credentials? {
        guard let data = self.data(forKey: storeKey),
              let credentials = NSKeyedUnarchiver.unarchiveObject(with: data) as? Credentials else {
            return nil
        }
        return credentials
    }
}

However, this unnecessarily exposes the A0SimpleKeychain as well as the way the credentials are persisted using NSKeyedUnarchiver. So if the Auth0.CredentialsManager way of archiving the credentials would change, the above code would likely fail.

@JanC JanC added the feature request A feature has been asked for or suggested by the community label Dec 29, 2020
@Widcket
Copy link
Contributor

Widcket commented Feb 10, 2021

Hi @JanC, we'll look into adding a way to retrieve the user profile separately from the credentials in the next major. This is unlikely to happen for the current 1.x. Will close this for now.

@Widcket Widcket closed this as completed Feb 10, 2021
@JanC
Copy link
Author

JanC commented Feb 23, 2021

thanks for your answer @Widcket

This is unlikely to happen for the current 1.x.

Even if I make a PR ? :)

cheers

@Widcket
Copy link
Contributor

Widcket commented Feb 24, 2021

We'll discuss this internally and come back to you.

@Widcket Widcket reopened this Feb 25, 2021
@Widcket
Copy link
Contributor

Widcket commented Feb 25, 2021

@JanC thanks for the offer, we'll happily take a PR that implements this. Might probably want to return an instance of UserInfo. Please ping if you have any questions or want to discuss something further.

@JanC
Copy link
Author

JanC commented Feb 25, 2021

ok, I have a branch somewhere with pretty much the implementation I posted in my original comment. I'll clean it up + write tests and will submit a PR. I'll look at the UserInfo

@stale
Copy link

stale bot commented Jun 2, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you have not received a response for our team (apologies for the delay) and this is still a blocker, please reply with additional information or just a ping. Thank you for your contribution! 🙇‍♂️

@stale stale bot added the closed:stale Issue or PR has not seen activity recently label Jun 2, 2021
@Widcket Widcket removed the closed:stale Issue or PR has not seen activity recently label Jun 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request A feature has been asked for or suggested by the community help wanted
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants