我正在使用下面的代码来验证我的Azure试用帐户中的默认用户。
static void Main(string[] args)
{
GetTokenAsync().Wait();
}
static async Task<string> GetTokenAsync()
{
string Tenant = "mytest.onmicrosoft.com";
string Authority = "https://login.microsoftonline.com/" + Tenant;
string GatewayLoginUrl = "https://login.microsoftonline.com/something/wsfed";
string ClientId = "something";
Uri RedirectUri = new Uri("http://something");
AuthenticationContext context = new AuthenticationContext(Authority);
PlatformParameters platformParams = new PlatformParameters(PromptBehavior.Auto, null);
AuthenticationResult result = await context.AcquireTokenAsync(GatewayLoginUrl, ClientId, RedirectUri, platformParams);
return result.ToString();
}
我想知道从哪里得到这些价值:
对于使用AD的用户身份验证来说,这些代码足够吗?
发布于 2018-01-03 10:27:52
在使用Azure Active保护应用程序时,有几种场景(请参阅这里):
以下是Azure AD支持的五种主要应用程序场景:
你说你已经注册了一份本机申请。我假设您需要对Azure Active Directory (AAD )进行身份验证,以便访问受保护的web或web应用程序(场景3),因此您也必须注册该目录。
static void Main(string[] args)
{
GetTokenAsync().Wait();
}
static async Task<string> GetTokenAsync()
{
string Tenant = "mytest.onmicrosoft.com";
string Authority = "https://login.microsoftonline.com/" + Tenant;
string GatewayLoginUrl = "https://login.microsoftonline.com/something/wsfed";
string ClientId = "something";
Uri RedirectUri = new Uri("http://something");
AuthenticationContext context = new AuthenticationContext(Authority);
PlatformParameters platformParams = new PlatformParameters(PromptBehavior.Auto, null);
AuthenticationResult result = await context.AcquireTokenAsync(GatewayLoginUrl, ClientId, RedirectUri, platformParams);
return result.ToString();
}
Tenant
是AAD域名,看来你说得对Authority
是"https://login.microsoftonline.com/" + Tenant
,所以看来你也猜对了GatewayLoginUrl
是您要保护的应用程序的AppClientId
是本机应用程序的应用程序Id。RedirectUri
是本机应用程序的重定向Uri。应用程序保护:
你从这里得到GatewayLoginUrl
。
访问要保护的应用程序的本机应用程序:
从这里可以得到ClientId
和RedirectUri
。
其他参考资料
您可以看到本机应用程序这里的完整演练。
有关使用本机应用程序访问受AAD保护的应用程序的全局概述,请参阅医生们。
https://stackoverflow.com/questions/48076102
复制相似问题