locked
Getting Owin Authorization token with AJAX RRS feed

  • Question

  • User1642115476 posted

    Hello,

    I'm working on a web API and I'm trying to implement an Owin Authorization token.

    I've got this in the backend:

    public class SimpleAuthorizationServerProvider : OAuthAuthorizationServerProvider
    {
    public override async Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
    {
    context.Validated();
    }

    public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
    {

    context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });

    using (AuthRepository _repo = new AuthRepository())
    {
    IdentityUser user = await _repo.FindUser(context.UserName, context.Password);

    if (user == null)
    {
    context.SetError("invalid_grant", "The user name or password is incorrect.");
    return;
    }
    }

    var identity = new ClaimsIdentity(context.Options.AuthenticationType);
    identity.AddClaim(new Claim("sub", context.UserName));
    identity.AddClaim(new Claim("role", "user"));

    context.Validated(identity);

    }
    }

    And it seems to pass the test in PostMan:

    Now what I would like to know is how this would look as an AJAX call. Note that there are two sets of data in the PostMan screen shot: headers and body. These are the sets of data I'd like to know how to put them in an AJAX call.

    Thanks.

    Friday, September 30, 2016 2:07 AM

Answers

All replies