Skip to content

Authenticate member via access_token #57

Open
@stefankip

Description

I've been looking for a way to authenticate a member when the access_token is supplied via query string for example.
So I have to authenticate without the use of any web api or MVC attribute.
For now I have this, but I had to copy over some internal stuff from the package, so I guess there should be a nicer way:

if (!string.IsNullOrEmpty(Request.QueryString["access_token"]))
{
    const string realm = "default";
    var oAuthContext = OAuth.GetContext(realm);
    var principal = oAuthContext.Services.TokenService.ReadToken(Request.QueryString["access_token"]);

    if (PrincipalHelper.ValidatePrincipal(principal, realm, oAuthContext.Services.UserService))
    {
        var name = principal.Identity.Name; // ToDo: log member in via username
    }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions