JamesRandall / AngularJS-OAuth2

Package for allowing an AngularJS application to authenticate with an OAuth 2 / Open ID Connect identity provider using the implicit flow.
MIT License
46 stars 42 forks source link

Technique to access and decode Identity Token #12

Closed pinnprophead closed 8 years ago

pinnprophead commented 8 years ago

I'm trying to figure out how to get the Identity Token after sign-in to determine user claims like email address, username etc. Since the page reloads after going to the Login, how can you catch the identity token and parse it?

JamesRandall commented 8 years ago

Hi pinprophead, what kind of application is it? I'm guessing MVC / ASP.Net. You should be able to cast the User property on the controller to a ClaimsPrincipal and this in turn as a Claims property that contains all the various claims. There's an example here:

https://github.com/JamesRandall/AngularJS-OAuth2-IdentityServer3-Sample/blob/master/IdentityServerSample.STS/Controllers/HomeController.cs#L20

Let me know if you're using some other form of technology and I'll try to help.

pinnprophead commented 8 years ago

Actually I was talking about on the angular client. What I want to do is get the Identity Token and extract the user's email address. This issue was reported on an earlier version of the angularjs-oauth2 component, and I just updated it. It now is behaving quite a bit differently, so I will dig into it again.

JamesRandall commented 8 years ago

Handily they're basically just base 64 url encoded strings, I've used this simple library here for doing it in JavaScript land https://github.com/auth0/jwt-decode. Hope that helps!