春季启动授权问题,来自Azure AD Auth Server的角色
根据此,我们用Azure AD实现了Spring Boot Auth: https://ordina-jworks.github.io/security/2020/08/18/securing-applications-applications-azure-ad.html
在这里,访问令牌验证正常,但不显示任何当局:
SecurityContext securityContext = SecurityContextHolder.getContext();
Authentication authentication = securityContext.getAuthentication();
Collection<? extends GrantedAuthority> authoritiesFromToken = authentication.getAuthorities();
System.out.println("authoritiesFromToken: " + authoritiesFromToken);
使用了以下依赖项:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-resource-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-oauth2-jose</artifactId>
</dependency>
添加了App AD中的App角色:https://learn.microsoft.com/en-us/azure/active-directory/develop/howto-add-app-roles-in-azure-ad-apps
使用Postman获得客户凭据的Azure AD令牌: https://learn.microsoft.com/en-us/rest/rest/rest/servicebus/get-azure-azure-active-directory-token
在此运行该应用程序之后set to the application is not printed.
我们还需要做什么才能扮演角色?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我们需要添加
范围:OpenID,配置文件
在application.yml文件中获取用户的个人资料信息。
we need add
scope: openid,profile
in application.yml file to get the profile information of user.
roles you are looking for can be present in the id token.
身份验证刀片或通过单独检查。
如果您没有在请求参数中分配资源
以及(client_id,grant_type等)。默认情况下资源
也许像00000002-0000-0000-C000-000000000000。也可以通过发送
响应类型=在请求中的令牌。
请检查此使用Azure Active Directory(aaddevsup.xyz)的Spring Boot启动器(aaddevsup.xyz) Azure Ad Ad保护的Web API
将以下依赖项添加到您的pom.xml文件中。
根据此处的注释,添加应用程序角色并从令牌-Microsoft Identity Platform |微软文档
角色也可以直接添加在清单JSON文件中。
检查用户。阅读是图形API,要获得应用程序的api代币,应在API上示出范围,并授予管理员同意的API权限。
要了解如何将授权添加到您的Web API中,请参见受保护的Web API:验证范围和应用程序角色。
参考:
Azure Active Directory开发人员指南的春季启动器|微软文档
roles you are looking for can be present in the id token.
authentication blade or try by checking both individually.
if you were not assigning a resource in request parameters
along with (client_id, grant_type, etc.) . By default the resource
maybe something like 00000002-0000-0000-c000-000000000000. Also try by sending
responseType =token in the request.
Please check this Azure AD-protected Web API using Spring Boot Starter for Azure Active Directory (aaddevsup.xyz)
Add the following dependencies to your pom.xml file.
According to note here in Add app roles and get them from a token - Microsoft identity platform | Microsoft Docs
The roles could also be added directly in the manifest json file.
Check the user.read is for graph api and to get token for api for your app should have the scope exposed for api.and granted api permissions for admin consent.
To learn how to add authorization to your web API, see Protected web API: Verify scopes and app roles.
Reference :
Spring Boot Starter for Azure Active Directory developer's guide | Microsoft Docs