AADSTS70011:为输入参数提供的值无效。 [英] AADSTS70011: The provided value for the input parameter 'scope' is not valid

查看:0
本文介绍了AADSTS70011:为输入参数提供的值无效。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个场景,其中应用程序应该在某些条件下将用户添加到组中。此外,当应用程序开始运行时,不应要求用户登录他们的Microsoft ID/PWD。

因此,我使用Graph Service客户端对象访问我创建的令牌,如下所示:

    GraphServiceClient graphClient = new GraphServiceClient(
        "https://graph.microsoft.com/v1.0", 
        new DelegateAuthenticationProvider(
            async (requestMessage) =>
            {
                string clientId = "My APP ID";
                string authorityFormat = "https://login.microsoftonline.com/{0}/v2.0";
                string tenantId = "tenant GUID";
                string[] _scopes = new string[] { 
                    "https://graph.microsoft.com/User.ReadBasic.All" 
                };
                // Custom Redirect URI asigned in the Application Registration 
                // Portal in the native Application Platform
                string redirectUri = "https://localhost:4803/"; 
                string clientSecret = "App Secret";
                ConfidentialClientApplication daemonClient = new ConfidentialClientApplication(
                    clientId, 
                    String.Format(authorityFormat, tenantId), 
                    redirectUri, 
                    new ClientCredential(clientSecret), 
                    null, new TokenCache()
                );
                AuthenticationResult authResult = await daemonClient.AcquireTokenForClientAsync(_scopes);
                string token = authResult.AccessToken;
                requestMessage.Headers.Authorization = new AuthenticationHeaderValue("bearer", token);
            }
       )
    );

所以我尝试执行 var user = await graphClient.Me.Request().GetAsync();

我收到此错误:

AADSTS70011:为输入参数‘Scope’提供的值无效。作用域User.Read无效。

我还尝试仅使用User.ReadBasic作为作用域,但遇到相同的错误。

我做错了什么?

推荐答案

您在这里使用的是客户端凭据流,这意味着您不能动态请求作用域。您必须在apps.dev.microsoft.com中的应用注册上配置所需的权限作用域,然后在代码中将作用域的值设置为https://graph.microsoft.com/.default

有关详细信息,请参阅https://developer.microsoft.com/en-us/graph/docs/concepts/auth_v2_service

这篇关于AADSTS70011:为输入参数提供的值无效。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆