Jump to content
Obi1-Cannabis

return extra data from GrantResourceOwnerCredentials

Recommended Posts

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...