Install-Package Newtonsoft.Json
The access token is just base64 encoded JSON. You can parse the token as follows
string token =
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ";
var parts = token.Split('.');
var decoded = Convert.FromBase64String(parts[1]);
var part = Encoding.UTF8.GetString(decoded);
var jwt = JObject.Parse(part);
var name = jwt["name"].Value<string>();
UPDATE
- Parsing access token on the client is not recommended, access token
should be parsed only on the resource server.
- You must validate the access token on the resource server to make
sure that token has not tampered on the way.
Most of the time you dont need to parse token as above, Just use a
recommended JWT library that does both validation and parsing. e.g.
app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());