I am developing a web service using ASP.NET Web API. I am using ASP.NET Identity for authentication and token generation. I need to return an extended property in token response json. Till now I am able to return an extended string property in which I am sending a json string obtained by serializing a custom class object into json. Following is my auth provider code:
public class ApplicationOAuthProvider : OAuthAuthorizationServerProvider
{
public override async Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
{
await Task.Run(() =>
{
context.Validated();
});
}
public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
{
await Task.Run(() =>
{
var loginResponse = new AccountManager().Login(context.UserName, context.Password);
if (loginResponse == null)
{
context.SetError("invalid_grant", Resources.Messages.InvalidGrant);
return;
}
var identity = new ClaimsIdentity(context.Options.AuthenticationType);
IDictionary<string, string> data = new Dictionary<string, string>
{
{ "userData", JsonConvert.SerializeObject(loginResponse) }
};
AuthenticationProperties properties = new AuthenticationProperties(data);
Microsoft.Owin.Security.AuthenticationTicket ticket = new Microsoft.Owin.Security.AuthenticationTicket(identity, properties);
context.Validated(ticket);
});
}
public override Task TokenEndpoint(OAuthTokenEndpointContext context)
{
foreach (KeyValuePair<string, string> property in context.Properties.Dictionary)
{
context.AdditionalResponseParameters.Add(property.Key, property.Value);
}
return Task.FromResult<object>(null);
}
}
Now in my response I have a property e.g. "userData" : "<Json String>"
whereas I wanted to assign a json object (not json string) to userData. Is it possible?