Click here to Skip to main content
14,270,034 members
Rate this:
Please Sign up or sign in to vote.
Hey there,

I need to pass some custom information with my JSON Web Token in web api.
Right now it only returns access_token,expires_in and token_type properties but I need to pass some additional information along with those properties like user_name,user_roles etc. I now the json token contains these information in encoded format but as my api will be consume by other platforms like android and ios so, I need to pass these information in plain text format.
Currently I am using following code to pass custom information with JSON token but I am getting same response as before.

Dictionary<string,> d = new Dictionary<string,>();
d.Add("user_name", user.UserName);
var props = new AuthenticationProperties(d);
ClaimsIdentity oAuthIdentity = await user.GenerateUserIdentityAsync(userManager, "JWT");
var ticket = new AuthenticationTicket(oAuthIdentity, props);

Below is the response of my web api:-

access_token: "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJuYW1laWQiOiIxNzViNzAxNC03M2YwLTQzNjctOGE0NC1iNmMxZjczNjc1MzAiLCJ1bmlxdWVfbmFtZSI6IkFkbWluIiwiaHR0cDovL3NjaGVtYXMubWljcm9zb2Z0LmNvbS9hY2Nlc3Njb250cm9sc2VydmljZS8yMDEwLzA3L2NsYWltcy9pZGVudGl0eXByb3ZpZGVyIjoiQVNQLk5FVCBJZGVudGl0eSIsIkFzcE5ldC5JZGVudGl0eS5TZWN1cml0eVN0YW1wIjoiYjdjMzQ5MmEtMDRmZC00OTQwLThjZDktYjEzMWRmNjFmMzIyIiwicm9sZSI6WyJVc2VyIiwiUHVibGlzaGVyIiwiQWRtaW4iXSwiaXNzIjoiaHR0cDovL2xvY2FsaG9zdDo1OTgyMiIsImF1ZCI6IjEyMzQ1Njc4IiwiZXhwIjoxNDc2NDUzNzI3LCJuYmYiOjE0NDUzNDk3Mjd9.wxstrUpUZSD1v5t1-F5_DVBrqpD7Yxq5Tsx6bnugVYQ"
token_type: "bearer"
expires_in: 31103999

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100