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

Feature: idTokenData new IAuthContext value #47

Closed
github-gael-soude opened this issue Dec 14, 2022 · 3 comments · Fixed by #48
Closed

Feature: idTokenData new IAuthContext value #47

github-gael-soude opened this issue Dec 14, 2022 · 3 comments · Fixed by #48

Comments

@github-gael-soude
Copy link

github-gael-soude commented Dec 14, 2022

It could be great if we had idTokenData in the useContext.

Today I have to reprocess the idToken decoding inside my react code.
It adds a few complexity when it could be done easily directly in the library as for tokenData.

The decoded idToken can be used for example to display the groups of the logged user.

interface IAuthContext {
  // The access token. This is what you will use for authentication against protected API's
  token: string
  // An object with all the properties encoded in the token (username, email, etc.)
  tokenData?: TTokenData
  // Login the user
  login: () => void  
  // Logout the user from the auth provider
  logOut: () => void
  // Keeps any errors that occured during login or token fetching/refreshing. 
  error: string | null
  // The idToken, if it was returned along with the access token
  idToken?: string
  // An object with all the properties encoded in the ID token (username, groups, etc.)
  idTokenData?: TTokenData
  // If the <AuthProvider> is done fetching tokens or not. Usefull for controlling page rendering
  loginInProgress: boolean
}
@sebastianvitterso
Copy link
Collaborator

I don't have the domain knowledge on OAuth, nor do I know the fundamental differences between these two token types. I think @soofstad will have to answer this.

@soofstad
Copy link
Owner

soofstad commented Dec 16, 2022

Absolutely @github-gael-soude, the library already has the capability to decode JWT's, so adding this should be fairly simple.
I think I wanted to keep the interfaces as small as possible in the beginning, but it has evolved into more of a swiss-army-knife with lots of options and features. And so it makes sense to add this.

Are you willing/able to create a PR for this @github-gael-soude? 🙂

@github-gael-soude
Copy link
Author

@soofstad thanks a lot.
I was off last week, but next time I can do the PR :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants