更新:のMicrosoftのAzure Active Directory認証のログインURL
As suggested I changed my Startup.auth.cs to code below
public partial class Startup
{
private static string clientId = ConfigurationManager.AppSettings["ida:ClientId"];
private static string appKey = ConfigurationManager.AppSettings["ida:ClientSecret"];
private static string aadInstance = ConfigurationManager.AppSettings["ida:AADInstance"];
private static string tenantId = ConfigurationManager.AppSettings["ida:TenantId"];
private static string postLogoutRedirectUri = ConfigurationManager.AppSettings["ida:PostLogoutRedirectUri"];
public static readonly string Authority = aadInstance + tenantId;
// This is the resource ID of the AAD Graph API. We'll need this to request a token to call the Graph API.
string graphResourceId = "https://graph.windows.net";
public void ConfigureAuth(IAppBuilder app)
{
ApplicationDbContext db = new ApplicationDbContext();
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions
{
ClientId = clientId,
Authority = Authority,
PostLogoutRedirectUri = postLogoutRedirectUri,
Notifications = new OpenIdConnectAuthenticationNotifications()
{
// If there is a code in the OpenID Connect response, redeem it for an access token and refresh token, and store those away.
AuthorizationCodeReceived = (context) =>
{
var code = context.Code;
ClientCredential credential = new ClientCredential(clientId, appKey);
string signedInUserID = context.AuthenticationTicket.Identity.FindFirst(ClaimTypes.NameIdentifier).Value;
AuthenticationContext authContext = new AuthenticationContext(Authority, new ADALTokenCache(signedInUserID));
AuthenticationResult result =
authContext.AcquireTokenByAuthorizationCode(
code,
new Uri(HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Path)),
credential,
graphResourceId);
return Task.FromResult(0);
},
RedirectToIdentityProvider = context =>
{
string appBaseUrl = context.Request.Scheme + "://" + context.Request.Host + context.Request.PathBase;
string currentUrl = context.Request.Scheme + "://" + context.Request.Host + context.Request.Path;
context.ProtocolMessage.RedirectUri = currentUrl;
context.ProtocolMessage.PostLogoutRedirectUri = appBaseUrl;
return Task.FromResult(0);
}
}
});
}
}
そして今、私はこれがあります。
時々DbEntityValidationExceptionは私ApplicationDbContextで発生(ストアに使用しますADALTokenCache)
ユーザー認証のためにAzure ADOu Office 365を使用してWebアプリケーションをコーディングする場合は、ログイン後にアプリケーションキーを作成し、AzureのURLをアプリケーションにリダイレクトする必要があります。 このurlはweb.configで設定する必要がありますが、Azure ADはアプリケーションが送信するURIパラメータを無視し、開発URIではなくプロダクションURIにリダイレクトします。
私の開発URL: https://localhost:44315/ 生産URL: http://timesheet.tecnun.com.br/アプリケーションは、web.configファイルを無視し、常に生産のURL
web.configファイルにリダイレクトします:
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
<add key="ida:ClientId" value="xxxxx" />
<add key="ida:AADInstance" value="https://login.microsoftonline.com/" />
<add key="ida:ClientSecret" value="xxxx" />
<add key="ida:Domain" value="tecnun.com.br" />
<add key="ida:TenantId" value="xxx" />
<add key="ida:PostLogoutRedirectUri" value="https://localhost:44315/" />
</appSettings>
Id 2つの環境、開発、生産/現場で作業するのが好きです。しかし、私は2つのアプリケーションを作成せずにこれを行う方法を見つけることができません。
どのようにURLを使用すると、リダイレクトされているに見えますか?あなたはそれらを正しく登録しましたか? – juunas
これが本当に問題ない場合は、[Graph Explorer](https://graphexplorer.cloudapp.net/)でアプリのサービスプリンシパルを見つけて、そこにある返信URLを確認することをお勧めします。 – juunas
URLはどのようなものですか?アプリケーションの設定方法詳細をご記入ください。 –