return extra data from GrantResourceOwnerCredentials

1 post in this topic

Is it possible to extend the OAuthGrantResourceOwnerCredentialsContext class from Microsoft.Owin.Security.OAuth?

when implementing my custom OAuthProvider I want to be able to add a new IList to the context in order to send messages that will be intercepted by Growl in AngularJs. what i want to do in case of an error for example is something like:

public class CustomOAuthProvider : OAuthAuthorizationServerProviderExtended{    //removed code for brevity    public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContextExtended context)    {       //removed code for brevity       ApplicationUser user = await userManager.FindAsync(context.UserName, context.Password);       if (user == null)       {           context.messages.Add(GeneralEx.CreateGrowlMessage("The company, user name or password is incorrect.", "error"));           return;       }       //removed code for brevity   }}

where CreateGrowlMessage is

public static GrowlMessage CreateGrowlMessage(string message, string severity)    {        GrowlMessage growlMessage = new GrowlMessage();        growlMessage.text = message;        growlMessage.severity = severity;        return growlMessage;    }

and GrowlMessage is

public class GrowlMessage{    public string text;    public string severity;}

I was trying to extend both OAuthAuthorizationServerProvider and OAuthGrantResourceOwnerCredentialsContext shown bellow

public class OAuthAuthorizationServerProviderExtended : OAuthAuthorizationServerProvider    {        public virtual Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContextExtended context)        {            return Task.FromResult<object>(null);        }    }    public class OAuthGrantResourceOwnerCredentialsContextExtended : OAuthGrantResourceOwnerCredentialsContext    {        public OAuthGrantResourceOwnerCredentialsContextExtended(IOwinContext context, OAuthAuthorizationServerOptions options, string clientId, string userName, string password, IList<string> scope)            : base(context, options, clientId, userName, password, scope)        {        }        public IList<GrowlMessage> messages {get;set;}    }

but this is not having the desired effect. now all login attempts fail and all i get in the response is {"error":"invalid_grant"}

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now