Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/302.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# UserAssertion缺少断言,不知道从何处获取_C#_.net_Oauth_Azure Active Directory - Fatal编程技术网

C# UserAssertion缺少断言,不知道从何处获取

C# UserAssertion缺少断言,不知道从何处获取,c#,.net,oauth,azure-active-directory,C#,.net,Oauth,Azure Active Directory,因此,我有以下代码,我正试图使用它代表用户获取访问令牌,以从graph api收集信息 config.Log.WriteLine(LogLevel.Full, "Gathering OAuth Tokens for " + config.Username + " at " + config.Authority); try { Authentication

因此,我有以下代码,我正试图使用它代表用户获取访问令牌,以从graph 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;
            }
config.Log.WriteLine(LogLevel.Full,“在“+config.Authority”处为“+config.Username+”收集OAuth令牌);
尝试
{
AuthenticationContext ac=新的AuthenticationContext(config.Authority);
ClientCredential cc=新的ClientCredential(config.AppKey,config.AppSecret);
ClientCredential clientCred=新的ClientCredential(config.AppKey,config.AppSecret);
UserAssertion ua=newuserassertion(//这是什么&我如何得到它,
“urn:ietf:params:oauth:grant-type:jwt-bearer”,
config.Username);
任务属性“”的来源?断言类型也是一个谜,我找不到ok类型的列表,但在我在网上看到的所有示例中,它们似乎都使用了我输入的一个,但并不能真正帮助我获得断言本身。

有什么帮助吗?谢谢这是一个jwt承载令牌,您可以从您的
HttpContext

var httpContext = _httpContextAccessor.HttpContext;

//Get the access token used to call this API
string token = await httpContext.GetTokenAsync("access_token");
//We are passing an *assertion* to Azure AD about the current user
//Here we specify that assertion's type, that is a JWT Bearer token
string assertionType = "urn:ietf:params:oauth:grant-type:jwt-bearer";

var userAssertion = new UserAssertion(token, assertionType, userName);


检查本指南中的全流量:


当然,我假设您使用的是MVC。您也可以从授权上下文中获取它

您好,谢谢您的回复,不要假设您可以解释如何从授权上下文中获取它,因为我已经在使用MVC,而不是使用HttpContext,所以这似乎是一个明智的选择,但我找不到任何方法可以让我获得它什么代币?