0
私はASP.NET WEB APIの複数のクライアントアプリケーションを開発中です。最初のクライアントはユーザー名とパスワードで認証し、2番目の認証はコード(文字列タイプ)で認証します。複数のプロバイダweb api
同じアプリで複数のプロバイダを使用することはできますか?私はまた、コードを確認
public void ConfigureAuth(IAppBuilder app)
{
app.CreatePerOwinContext(ApplicationDbContext.Create);
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
// Configure the application for OAuth based flow
PublicClientId = "self";
OAuthOptions = new OAuthAuthorizationServerOptions
{
TokenEndpointPath = new PathString("/Token"),
Provider = new ApplicationOAuthProvider(PublicClientId),
AuthorizeEndpointPath = new PathString("/api/Account/ExternalLogin"),
AccessTokenExpireTimeSpan = TimeSpan.FromDays(14),
// In production mode set AllowInsecureHttp = false
AllowInsecureHttp = true
};
app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
}
私ApplicationOAuthProviderクラスではなく、最初のアプリは、コードを使用していません: は、ここでは、コードです。
public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
{
var userManager = context.OwinContext.GetUserManager <ApplicationUserManager>();
ApplicationUser user = await userManager.FindAsync(context.UserName, context.Password);
ApplicationUser userByName = await userManager.FindByNameAsync(context.UserName);
var data = await context.Request.ReadFormAsync();
var code = data["code"];
if (userByName == null || userByName.Code != code)
{
context.SetError("invalid_grant", "The user name or password is incorrect.");
return;
}
ClaimsIdentity oAuthIdentity = await userByName.GenerateUserIdentityAsync(userManager, OAuthDefaults.AuthenticationType);
ClaimsIdentity cookiesIdentity = await userByNameCristina.GenerateUserIdentityAsync(userManager,
CookieAuthenticationDefaults.AuthenticationType);
AuthenticationProperties properties = CreateProperties(userByNameCristina.UserName,data["code"]);
AuthenticationTicket ticket = new AuthenticationTicket(oAuthIdentity, properties);
context.Validated(ticket);
context.Request.Context.Authentication.SignIn(cookiesIdentity);
}