小编Pop*_*eye的帖子

SpringBoot OAuth2 示例应用程序

应用程序.yml

server:
  port: 8082

spring:
  security:
    oauth2:
      client:
        registration:
          custom-client:
            client-id: R2dpxQ3vPrtfgF72
            client-secret: fDw7Mpkk5czHNuSRtmhGmAGL42CaxQB9
            client-name: Auth Server
            scope: user_info
            provider: custom-provider
            redirect-uri-template: http://localhost:8082/login/oauth2/code/
            client-authentication-method: basic
            authorization-grant-type: authorization_code
        provider:
          custom-provider:
            token-uri: http://localhost:8081/auth/oauth/token
            authorization-uri: http://localhost:8081/auth/oauth/authorize
            user-info-uri: http://localhost:8081/auth/user/me
            user-name-attribute: name
Run Code Online (Sandbox Code Playgroud)

WebSecurityConfigurerAdapter 的扩展

@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
    @Override
    public void configure(HttpSecurity http) throws Exception {

        http.antMatcher("/**") //
                .authorizeRequests()//
                .antMatchers("/", "/login**")//
                .permitAll() //
                .anyRequest() //
                .authenticated() //
                .and() //
                .oauth2Login();

    }

}
Run Code Online (Sandbox Code Playgroud)

依赖

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>
    <dependency>
        <groupId>com.sun.mail</groupId> …
Run Code Online (Sandbox Code Playgroud)

client-server oauth-2.0 spring-boot openjdk-11

4
推荐指数
1
解决办法
2971
查看次数