【发布时间】:2020-09-24 01:18:27
【问题描述】:
所以我有以下代码,我试图用它来代表用户获取访问令牌,以从图形 api 收集信息。
config.Log.WriteLine(LogLevel.Full, "Gathering OAuth Tokens for " + config.Username + " at " + config.Authority);
try
{
AuthenticationContext ac = new AuthenticationContext(config.Authority);
ClientCredential cc = new ClientCredential(config.AppKey, config.AppSecret);
ClientCredential clientCred = new ClientCredential(config.AppKey, config.AppSecret);
UserAssertion ua = new UserAssertion(//WHAT IS THIS & HOW DO I GET IT,
"urn:ietf:params:oauth:grant-type:jwt-bearer",
config.Username);
Task<AuthenticationResult> re = ac.AcquireTokenAsync("https://graph.windows.net", cc.ClientId, ua);
while(!re.IsCompleted)
{
re.Wait();
}
oauthTokenCache = new OauthTokenCache(re.Result);
request.Headers.Add("Authorization", oauthTokenCache.authHeader);
}
catch (Exception e)
{
Console.WriteLine("Aquire Access Token Exception: " + e);
throw;
}
但我不知道UserAssertion 属性“assertion”的来源是什么?断言类型也是一个谜,我找不到 ok 类型的列表,但是在我在网上看到的所有示例中,它们似乎都使用了我输入的那个,但并没有真正帮助我获得断言本身。 有什么帮助吗?谢谢
【问题讨论】:
标签: c# .net oauth azure-active-directory