- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在设置一个 oauth 2.0 客户端应用程序,它将用户重定向到外部 IDP(授权服务器)以登录。我的应用程序将接受常规的 oauth 2 授权代码授予流程 - 1) 重定向用户以登录。2)首先获取访问代码 3) 使用访问代码获取 token 。由于外部 IDP 仅使用 oauth 2 进行身份验证,因此他们不会提供用户信息端点 url(OIDC 提供商需要)来获取用户详细信息。相反,他们希望我们直接从 JWT token 中获取声明并在我们的应用程序中进行任何授权。
我无法找到正确的代码/配置,它不需要用户信息端点,而是直接解码 jwt 以加载身份验证。
在下面的演示代码中,如果我要从 OKTA 发布的 JWT token 中解码用户详细信息而不调用其 userInfo 端点,我该怎么做?
我正在使用 spring boot 2.x 版本,使用 spring 引用示例社交 oauth2 项目中提供的标准 oauth 客户端配置。
如果有人能指导我走正确的道路,我将不胜感激。谢谢!
梯度配置
buildscript {
ext {
springBootVersion = '2.2.0.RELEASE'
}
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenLocal()
mavenCentral()
}
configurations {
compile.exclude module: 'spring-boot-starter-logging'
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-web:${springBootVersion}")
compile("org.springframework.boot:spring-boot-starter-log4j2:${springBootVersion}")
compile("org.springframework.boot:spring-boot-starter-security:${springBootVersion}")
compile("org.springframework.security.oauth.boot:spring-security-oauth2-autoconfigure:${springBootVersion}")
compile("org.webjars:jquery:2.1.1")
compile("org.webjars:bootstrap:3.2.0")
compile("org.webjars:webjars-locator-core:0.42")
}
github:
client:
clientId: <clientId>
clientSecret: <clientSecret>
accessTokenUri: https://github.com/login/oauth/access_token
userAuthorizationUri: https://github.com/login/oauth/authorize
tokenName: oauth_token
authenticationScheme: query
clientAuthenticationScheme: form
resource:
userInfoUri: https://api.github.com/user
okta:
client:
clientId: <clientId>
clientSecret: <clientSecret>
accessTokenUri: https://<okta-sub-domain>/oauth2/default/v1/token
userAuthorizationUri: https://<okta-sub-domain>/oauth2/default/v1/authorize
scope: openid profile email
resource:
userInfoUri: https://<okta-sub-domain>/oauth2/default/v1/userinfo
@Configuration
@EnableOAuth2Client
public class Oauth2Config extends WebSecurityConfigurerAdapter {
@Autowired
OAuth2ClientContext oauth2ClientContext;
@Override
protected void configure(HttpSecurity http) throws Exception {
http.antMatcher("/**").authorizeRequests()
.antMatchers("/", "/login**", "/webjars/**", "/error**")
.permitAll()
.anyRequest()
.authenticated()
.and().logout().logoutSuccessUrl("/").permitAll()
.and().addFilterBefore(ssoFilter(), BasicAuthenticationFilter.class);;
http.csrf().disable();
}
private Filter ssoFilter() {
CompositeFilter filter = new CompositeFilter();
List<Filter> filters = new ArrayList<>();
OAuth2ClientAuthenticationProcessingFilter githubFilter = new OAuth2ClientAuthenticationProcessingFilter("/login/github");
OAuth2RestTemplate githubTemplate = new OAuth2RestTemplate(github(), oauth2ClientContext);
githubFilter.setRestTemplate(githubTemplate);
UserInfoTokenServices tokenServices = new UserInfoTokenServices(githubResource().getUserInfoUri(), github().getClientId());
tokenServices.setRestTemplate(githubTemplate);
githubFilter.setTokenServices(tokenServices);
filters.add(githubFilter);
OAuth2ClientAuthenticationProcessingFilter oktaFilter = new OAuth2ClientAuthenticationProcessingFilter("/login/okta");
OAuth2RestTemplate oktaTemplate = new OAuth2RestTemplate(okta(), oauth2ClientContext);
oktaFilter.setRestTemplate(oktaTemplate);
tokenServices = new UserInfoTokenServices(oktaResource().getUserInfoUri(), okta().getClientId());
tokenServices.setRestTemplate(oktaTemplate);
oktaFilter.setTokenServices(tokenServices);
filters.add(oktaFilter);
filter.setFilters(filters);
return filter;
}
//Client registration
@Bean
@ConfigurationProperties("github.client")
public AuthorizationCodeResourceDetails github() {
return new AuthorizationCodeResourceDetails();
}
//user info endpoints
@Bean
@ConfigurationProperties("github.resource")
public ResourceServerProperties githubResource() {
return new ResourceServerProperties();
}
@Bean
@ConfigurationProperties("okta.client")
public AuthorizationCodeResourceDetails okta() {
return new AuthorizationCodeResourceDetails();
}
@Bean
@ConfigurationProperties("okta.resource")
public ResourceServerProperties oktaResource() {
return new ResourceServerProperties();
}
//For Handling Redirects
@Bean
public FilterRegistrationBean<OAuth2ClientContextFilter> oauth2ClientFilterRegistration(OAuth2ClientContextFilter filter) {
FilterRegistrationBean<OAuth2ClientContextFilter> registration = new FilterRegistrationBean<>();
registration.setFilter(filter);
registration.setOrder(-100);
return registration;
}
@RestController
public class UserController {
@GetMapping("/user")
public Principal user(Principal principal) {
return principal;
}
@SpringBootApplication
public class Oauth2Application {
public static void main(String[] args) {
SpringApplication.run(Oauth2Application.class, args);
}
最佳答案
DefaultReactiveOAuth2UserService
查找用户信息。我们可以简单地介绍一个新的ReactiveOAuth2UserService
从 token 中获取值的实现,例如:
@Service
public class GttOAuth2UserService implements ReactiveOAuth2UserService<OAuth2UserRequest, OAuth2User> {
@Override
public Mono<OAuth2User> loadUser(OAuth2UserRequest oAuth2UserRequest) throws OAuth2AuthenticationException {
final List<GrantedAuthority> authorities = Arrays.asList(new SimpleGrantedAuthority("authority"));
final Map<String, Object> attributes = oAuth2UserRequest.getAdditionalParameters();
final OAuth2User user = new DefaultOAuth2User(authorities, attributes, "email");
return Mono.just(user);
}
}
(在你的情况下,它可能是非 react 性的等价物)
关于java - Spring 启动 oauth2 : No userInfo endpoint - How to load the authentication (Principal) from the JWT access token directly in the client,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58739445/
我正在学习 java,并研究了来自 sun.com 的以下示例。 import java.io.*; import java.util.*; public class UserInfo impleme
我需要根据 URI 子集来识别用户。它具有以下模式 http://userinfo@hostname:port/path。 java.net.URI implementation 表示 URI。但是,
我正在尝试使用以下 GET 访问 Office365 Azure 租户上用户的 OpenId UserInfo 端点: GET https://login.windows.net/common/ope
如何使用 org.apache.jackrabbit.api.security.user 获取 CQ5 用户信息像java或jsp中的名称和组信息。? 最佳答案 在 JSP/Java 中,您可以将您的
我正在做一个安排本地通知并保存用户信息的应用程序。这部分没问题。 但是当应用程序关闭时,如果出现 Notification 并且用户点击,则不会调用该方法,我无法处理 userInfo。 我看到有一种
使用 Swift 语言从 xCode 获取编译错误消息:“extra argument userinfo in call”。问题是如何使用定时器中的 userInfo 数据到通知中心的参数“userI
根据ASIHTTPRequest网站: If your requests are all of the same broad type, but you want to distinguish bet
实现下一个代码时: func locationManager(manager: CLLocationManager!, didChangeAuthorizationStatus status: CLA
我调用NotificationCenter的post方法时有一个方法: func processMessage(message: CocoaMQTTMessage) { Log.d("Dest
我需要使用 userInfo 填充推送通知的字段(.title 和 .body)。我什么都试过了,但我只能输入“日期”代码块。我能怎么做?谢谢。 这是我从控制台 php 发送推送通知时的输出: OUT
我正在尝试创建我的 userinfo 命令,您可以为任何用户执行此操作,并显示服务器中的语音时间和服务器中发送的消息这是我的!!userinfo 命令 const Discord = module.r
所以我一直想弄清楚为什么 userInfo 一直没有显示我想要的数据。当我打印 userInfo 时,我得到了这个: [AnyHashable("aps"): { alert = "test
我有一个来自 UILocalNotification 的 userInfo 字典。使用隐式展开时是否有一种简单的方法来获取 String 值? if let s = userInfo?["ID"] 给
我有一个返回字典的通知,很像在 objective-c 中,但我没有得到我期望的结果。 这是发布通知的方法。它实际上是返回日期选择器的结果(日期)。 @IBAction func dateOfBirt
由于 ADFS 4.0 隐式流不返回 id_token 中的自定义声明,我尝试从 userInfo 端点获取这些声明。要获取 userinfo 端点的访问 token ,必须使用资源 urn:micr
我一直在使用身份服务器快速启动应用程序,我想添加调用userinfo端点时要返回的角色信息。 public Claim[] GetUserClaims(UserServiceProxy.Dto.U
我正在我的应用程序中使用 NSManagedObjectContextObjectsDidChangeNotification 通知,我现在已经知道如何使用它了。因为我使用了下面的代码来添加观察者..
在那段代码中,我有两个 NSLog 都表示 dict 的保留计数为 1。由于如果数组中有很多对象,计时器可能会在很长一段时间内触发,我可以保留给用户信息的字典吗?因为我猜它是自动释放的,而schedu
在当前 header 中,它声明为: @property (nonatomic, readonly, strong) NSMutableDictionary *userInfo NS_AVAILABL
我正在尝试使用 NSNotification 发送一些数据,但遇到了困难。这是我的代码: // Posting Notification NSDictionary *orientationData;
我是一名优秀的程序员,十分优秀!