我有两个应用程序,一个是web-api应用程序(y.x.com),另一个是前端应用程序(z.x.com)。要对访问zxcom的用户进行身份验证,请按照visual studio 2015提供的web api模板代码使用ws-federation或microsoft live login。如果我直接从我的浏览器,邮递员,提琴手或者说话者谈论web api应用程序(yxcom)任何类似的身份验证工作正常,但如果我尝试从前端应用程序登录,我得到error: invalid_request
(状态400)。
现在我想知道是否应该可以通过调用y.x.com/Account/ExternalLogin?provider=Federation&response_type=token&client_id=self&redirect_uri=http://y.x.com
从应用程序z.x.com登录。
我在y.x.com中的startup.auth看起来像这样
OAuthOptions = new OAuthAuthorizationServerOptions
{
TokenEndpointPath = new PathString("/Token"),
Provider = new ApplicationOAuthProvider(PublicClientId),
AuthorizeEndpointPath = new PathString("/Account/ExternalLogin"),
AccessTokenExpireTimeSpan = TimeSpan.FromDays(14),
// In production mode set AllowInsecureHttp = false
AllowInsecureHttp = true
};
// Enable the application to use bearer tokens to authenticate users
app.UseOAuthBearerTokens(OAuthOptions);
var wsOptions = new WsFederationAuthenticationOptions
{
MetadataAddress = "https://login.microsoftonline.com/afd2d5a6-bdb1-43f8-a42b-83ec49f1f22d/federationmetadata/2007-06/federationmetadata.xml",
Wtrealm = "http://y.x.com/",
Notifications = new WsFederationAuthenticationNotifications()
};
app.UseWsFederationAuthentication(wsOptions);
我可以提供更多代码,但我最感兴趣的是,是否应该工作。 感谢。
答案 0 :(得分:1)
这是可能的。在som挖掘并帮助之后,事实证明在web-api模板中,类ValidateClientRedirectUri
中有一个名为ApplicationOAuthProvider
的方法。如果我将该方法更改为
public override Task ValidateClientRedirectUri(OAuthValidateClientRedirectUriContext context)
{
context.Validated();
return Task.FromResult<object>(null);
}
然后从我的前端应用程序,我现在可以获得任何我想要的返回URL,从而可以通过web-api应用程序从前端应用程序登录到外部源。