【发布时间】:2017-02-03 16:55:31
【问题描述】:
我有一个单租户云服务,我希望只有我公司的员工可以访问它。该解决方案具有 Web 角色和工作者角色。
Web.Config
<add key="ida:Tenant" value="MyCompany.onmicrosoft.com" />
<add key="ida:Audience" value="https://MyCompany.onmicrosoft.com/MySolutionWebRole" />
<add key="ida:ClientID" value="44421xxx-xxxx-xxxx-xxxx-xxxxxxx7024" />
<add key="ida:Password" value="i6fMxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx4Yk=" />
<add key="ida:AADInstance" value="https://login.microsoftonline.com/{0}" />
<add key="ida:PostLogoutRedirectUri" value="https://localhost:44322/" />
另外,我在 Cloud.config 中获得了相同的设置:
<Setting name="ida.Tenant" value="MyCompany.onmicrosoft.com" />
<Setting name="ida.Audience" value="https://MyCompany.onmicrosoft.com/MySolutionWebRole" />
<Setting name="ida.ClientID" vvalue="44421xxx-xxxx-xxxx-xxxx-xxxxxxx7024" />
<Setting name="ida.Password" value="i6fMxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx4Yk=" />
<Setting name="ida.AADInstance" value="https://login.microsoftonline.com/{0}" />
<Setting name="ida.PostLogoutRedirectUri" value="https://localhost:44322/" />
继续使用 Startup.Auth.cs
public void ConfigureAuth(IAppBuilder app)
{
string authority = String.Format(CultureInfo.InvariantCulture, aadInstance, tenant);
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions
{
ClientId = clientId,
Authority = authority,
PostLogoutRedirectUri = postLogoutRedirectUri,
RedirectUri = postLogoutRedirectUri,
Notifications = new OpenIdConnectAuthenticationNotifications
{
AuthenticationFailed = context =>
{
context.HandleResponse();
context.Response.Redirect("/Error?message=" + context.Exception.Message);
return Task.FromResult(0);
}
}
});
}
最后,我在控制器中设置了 [Authorize] 标签。
在 Azure Active Directory 设置中,我已经注册了我的云服务。 应用程序类型为 Web 应用程序/API,多租户为“否”。注销 url 设置为https://localhost:44322/Account/EndSession。我没有更改或编辑清单。
当我尝试进入云服务时,我被重定向到我的组织登录页面(到目前为止一切正常),但在输入密码后,我收到一条错误消息。
您无法登录。我们收到了非法请求。 (免费翻译)
相关 ID:21f4089f-1952-4f57-aead-173a66c1408d 时间戳: 2016-09-26 10:24:14Z AADSTS90093:此应用程序需要 另一个应用程序的应用程序权限。同意 应用程序权限只能由管理员执行。 注销并以管理员身份登录或联系您的 组织的管理员。
登录请求的url如下(我输入密码的界面);
https://login.microsoftonline.com/fd2xxxxxx-xxxx-xxxx-xxxxxxxf3f2/ oauth2/authorize?client_id=444xxxxxx-xxxx-xxxx-xxxxxxxx024 &redirect_uri=https%3a%2f%2flocalhost%3a44322%2f &response_mode=form_post &response_type=code+id_token &scope=openid+profile&state=OpenIdConnect.AuthenticationProperties %3dYkxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
我一直在研究基于 Web 应用程序的两个示例解决方案,网址为 https://github.com/Azure-Samples/active-directory-dotnet-webapp-openidconnect 和 https://github.com/Azure-Samples/active-directory-dotnet-webapp-multitenant-openidconnect
如果能在这件事上提供任何帮助,我将不胜感激
【问题讨论】:
标签: azure authentication azure-active-directory azure-cloud-services