"静默获取令牌失败.调用方法 AcquireToken"

编程入门 行业动态 更新时间:2024-10-20 13:30:35
本文介绍了"静默获取令牌失败.调用方法 AcquireToken"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

试试{ClientCredential clientCredential = new ClientCredential("***********","**************");UserIdentifier userIdentifier = new UserIdentifier(userObjectId, UserIdentifierType.UniqueId);DiscoveryClient discClient = new DiscoveryClient(SettingsHelper.DiscoveryServiceEndpointUri,异步 () =>{var authResult = await authContext.AcquireTokenSilentAsync(SettingsHelper.DiscoveryServiceResourceId,clientCredential, userIdentifier);返回 authResult.AccessToken;});var dcr = await discClient.DiscoverCapabilityAsync(capabilityName);返回新的 OutlookServicesClient(dcr.ServiceEndpointUri,异步 () =>{var authResult = await authContext.AcquireTokenSilentAsync(dcr.ServiceResourceId, clientCredential, userIdentifier);返回 authResult.AccessToken;});}catch (AdalException 异常){//处理token获取失败if (exception.ErrorCode == AdalError.FailedToAcquireTokenSilently){authContext.TokenCache.Clear();抛出异常;}返回空;}

出现错误无法静默获取令牌.调用方法 AcquireToken"

解决方案

请确保应用已在 Office 365 租户 AD 下注册,否则您将无法发现和使用 Office 365 服务.

步骤#1 下载示例项目

步骤#3 在 web.config 文件中,从 Azure AD 门户复制 ClientId、TenantId 和 Client Secret.

Step#4 在 Visual Studio 中运行项目并使用 Azure AD 帐户登录

预期结果应如下:

如果您遇到令牌问题,也可以单击清除缓存数据库"按钮.

try
{
    ClientCredential clientCredential = new ClientCredential("***********","**************");
    UserIdentifier userIdentifier = new UserIdentifier(userObjectId, UserIdentifierType.UniqueId);

    DiscoveryClient discClient = new DiscoveryClient(SettingsHelper.DiscoveryServiceEndpointUri,
        async () =>
        {
            var authResult = await authContext.AcquireTokenSilentAsync(SettingsHelper.DiscoveryServiceResourceId,
                                                                       clientCredential, userIdentifier);

            return authResult.AccessToken;
        });

    var dcr = await discClient.DiscoverCapabilityAsync(capabilityName);

    return new OutlookServicesClient(dcr.ServiceEndpointUri,
        async () =>
        {
            var authResult = await authContext.AcquireTokenSilentAsync(dcr.ServiceResourceId, clientCredential, userIdentifier);
            return authResult.AccessToken;
        });
}
catch (AdalException exception)
{
    //Handle token acquisition failure
    if (exception.ErrorCode == AdalError.FailedToAcquireTokenSilently)
    {
        authContext.TokenCache.Clear();
        throw exception;
    }
    return null;
}

giving error "Failed to acquire token silently. Call method AcquireToken"

解决方案

Please ensure the app is registered under Office 365 tenant AD, else you will fail to discover and consume the Office 365 services.

Step#1 Download the sample project AspNetMvc-with-O365.zip.

Step#2 Register an app under Office 365 tenant AD, declare the Office 365 Exchange Online > Read user mail permission and set the REPLY URL as "http://localhost:2659/".

Step#3 In the web.config file, copy the ClientId, TenantId and Client Secret from Azure AD portal.

Step#4 Run the project in Visual Studio and log in with Azure AD account

The expected result should be as following:

You can also click the "Clear the cache database" button if you have acquire token issues.

这篇关于"静默获取令牌失败.调用方法 AcquireToken"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-18 05:17:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/930503.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:令牌   方法   amp   quot   AcquireToken

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!