38 lines
1.7 KiB
C#
38 lines
1.7 KiB
C#
|
|
using LDX.WebApi.Providers;
|
|||
|
|
using System;
|
|||
|
|
|
|||
|
|
namespace LDX.WebApi
|
|||
|
|
{
|
|||
|
|
public partial class StartupAuth
|
|||
|
|
{
|
|||
|
|
public static OAuthAuthorizationServerOptions OAuthOptions { get; private set; }
|
|||
|
|
|
|||
|
|
public static string PublicClientId { get; private set; }
|
|||
|
|
|
|||
|
|
// 有关配置身份验证的详细信息,请访问 http://go.microsoft.com/fwlink/?LinkId=301864
|
|||
|
|
public void ConfigureAuth(IAppBuilder app)
|
|||
|
|
{
|
|||
|
|
// 使应用程序可以使用 Cookie 来存储已登录用户的信息
|
|||
|
|
// 并使用 Cookie 来临时存储有关使用第三方登录提供程序登录的用户的信息
|
|||
|
|
//app.UseCookieAuthentication(new CookieAuthenticationOptions());
|
|||
|
|
//app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
|
|||
|
|
|
|||
|
|
// 针对基于 OAuth 的流配置应用程序
|
|||
|
|
OAuthOptions = new OAuthAuthorizationServerOptions
|
|||
|
|
{
|
|||
|
|
TokenEndpointPath = new PathString("/api/Token"),
|
|||
|
|
Provider = new ApplicationOAuthProvider(),//获取 access_token 认证服务请求地址
|
|||
|
|
AccessTokenExpireTimeSpan = TimeSpan.FromDays(10),
|
|||
|
|
AllowInsecureHttp = true,
|
|||
|
|
|
|||
|
|
AuthorizeEndpointPath = new PathString("/api/authorize"), //获取 authorization_code 授权服务请求地址
|
|||
|
|
AuthorizationCodeProvider = new OpenAuthorizationCodeProvider(), //authorization_code 认证服务
|
|||
|
|
RefreshTokenProvider = new OpenRefreshTokenProvider() //refresh_token 认证服务
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
// 使应用程序可以使用不记名令牌来验证用户身份:表示 token_type 使用 bearer 方式
|
|||
|
|
app.UseOAuthBearerTokens(OAuthOptions);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|