首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AADSTS65001:用户或管理员未同意使用ID <app-id>的应用程序

AADSTS65001:用户或管理员未同意使用ID <app-id>的应用程序
EN

Stack Overflow用户
提问于 2022-05-28 21:27:49
回答 1查看 7.4K关注 0票数 5

我正在开发一个使用微软OAuth2 (代表用户流)的角形+水瓶应用程序。我试图从后端调用一个API,但我得到了一个异常。

以下是app.module.ts中的配置

代码语言:javascript
复制
export function MSALInstanceFactory(): IPublicClientApplication {
  return new PublicClientApplication({
    auth: {
      clientId: '<application_id_of_spa>',
      authority: 'https://login.microsoftonline.com/organizations',
      redirectUri: 'http://localhost:4200/'
    },
    cache: {
      cacheLocation: BrowserCacheLocation.LocalStorage,
      storeAuthStateInCookie: isIE,
    },
    system: {
      loggerOptions: {
        loggerCallback,
        logLevel: LogLevel.Info,
        piiLoggingEnabled: false
      }
    }
  });
}

export function MSALInterceptorConfigFactory(): MsalInterceptorConfiguration {
  const protectedResourceMap = new Map<string, Array<string>>();
  protectedResourceMap.set('https://graph.microsoft.com/v1.0/me', ['user.read']);
  protectedResourceMap.set('https://api.powerbi.com/v1.0/myorg/', ['https://analysis.windows.net/powerbi/api/.default']);
  protectedResourceMap.set('http://localhost:5000/api/v1.0/get_workspaces',['api://<application_id_of_webapi>/.default'])

  return {
    interactionType: InteractionType.Popup,
    protectedResourceMap
  };
}

export function MSALGuardConfigFactory(): MsalGuardConfiguration {
  return { 
    interactionType: InteractionType.Popup,
    authRequest: {
      scopes: ['api://<application_id_of_webapi>/.default'],
    },
  };
}

然后,我使用acquireTokenPopup msal函数来获取访问令牌。

然后我像这样调用后端API:

代码语言:javascript
复制
this.http.get('http://localhost:5000/api/v1.0/get_workspaces')

我的水瓶网络API:

代码语言:javascript
复制
@app.route('/api/v1.0/get_workspaces', methods=['GET'])
def get():

        current_access_token = request.headers.get("Authorization", None)

        msal_client = msal.ConfidentialClientApplication(
            client_id=app.config['CLIENT_ID'],
            authority=app.config['AUTHORITY'],
            client_credential=app.config['CLIENT_SECRET'])

        # acquire token on behalf of the user that called this API
        arm_resource_access_token = msal_client.acquire_token_on_behalf_of(
            user_assertion=current_access_token.split(' ')[1],
            scopes=app.config['SCOPE']
        )
        print( arm_resource_access_token) /////////////////// ******* I'm getting the error here

        headers = {
            'Authorization': arm_resource_access_token['token_type'] + ' ' + arm_resource_access_token['access_token']}

        workspaces= requests.get(app.config['ENDPOINT'] + 'workspaces', headers = headers).json()
        print(workspaces)
        return jsonify(workspaces)

在我的角度控制台里,我得到了这个:

在我的酒瓶终端里,我得到了这个:

代码语言:javascript
复制
AADSTS65001: The user or administrator has not consented to use the application with ID <webapi_ app_id>.

在Azure门户网站上,我注册了spa和web:

我在后端公开了API,并将其添加到前端注册中。

我在授权的客户应用程序中添加了我的spa app_id。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-05-29 01:22:19

AADSTS65001:用户或管理员尚未同意使用应用程序

当您在检索访问令牌时没有向添加的范围授予管理同意书时,通常会发生此错误。

若要解决此错误,请检查是否公开了如下所示的API:

转到Azure Portal -> Azure Active Directory ->应用程序注册->公开API

在公开API之后,请确保为其授予API permissions,如下所示:

转到Azure Portal -> Azure Active Directory ->应用程序注册-> API权限->添加权限-> My ->您的API

  • 添加API权限后,如果需要,确保授予管理同意书

  • 在尝试获取访问令牌时,请检查是否启用了以下选项:

转到Azure Portal -> Azure Active Directory ->应用程序注册->身份验证

如果错误仍然存在,请检查下面的链接

azure active directory - InteractionRequiredAuthError: AADSTS65001: The user or administrator has not consented to use the application with ID - Stack Overflow

.net - "AADSTS65001: The user or administrator has not consented to use the application" occurs when token is acquired on behalf of a user - Stack Overflow

更新:

正如您在注释中提到的,请确保将客户端应用程序添加到已知客户端应用程序列表中。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72419373

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档