app.UseOAuthBearerTokens with ASP.NET Identity 2.0's DbContext middleware?

前端 未结 2 663
小鲜肉
小鲜肉 2021-02-03 16:15

Edit: After progressing, I can narrow the scope of the question:

What changes should be made to startup.auth.cs and ApplicationOAuthProvider.cs in the VS2013 SPA templat

2条回答
  •  眼角桃花
    2021-02-03 16:50

    The following is just the code from the SPA template with the provider for UserManager replaced with the stuff introduced in 2.0 Identity.

    OAuthOptions = new OAuthAuthorizationServerOptions
                {
                    TokenEndpointPath = new PathString("/Token"),
                    Provider = new ApplicationOAuthProvider(PublicClientId, () => HttpContext.Current.GetOwinContext().Get()),
                    AuthorizeEndpointPath = new PathString("/api/Account/ExternalLogin"),
                    AccessTokenExpireTimeSpan = TimeSpan.FromDays(14),
                    AllowInsecureHttp = false
                };
    

    Here is also a Generic ApplicationOauthProvider you can use: https://gist.github.com/s093294/9076631 (due note I haven't tested it and just put it together for you)

    Example if you have:

    app.CreatePerOwinContext(ApplicationUserManager.Create);
    

    you can do

            OAuthOptions = new OAuthAuthorizationServerOptions
            {
                TokenEndpointPath = new PathString("/Token"),
                Provider = new ApplicationOAuthProvider(PublicClientId),
                AuthorizeEndpointPath = new PathString("/api/Account/ExternalLogin"),
                AccessTokenExpireTimeSpan = TimeSpan.FromDays(14),
                AllowInsecureHttp = false
            };
    

提交回复
热议问题