OAuthSecurityConfig.java
@Configuration
public class OAuthSecurityConfig extends AuthorizationServerConfigurerAdapter {
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.inMemory()
.withClient("client")
.secret("secret")
.redirectUris("http://www.baidu.com")
.authorizedGrantTypes("authorization_code")
.scopes("app");
}
}
DemoApplication.java
@SpringBootApplication
@EnableAuthorizationServer
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
build.gradle
dependencies {
compile('org.springframework.boot:spring-boot-starter')
compile('com.auth0:java-jwt:2.2.0')
compile('org.springframework.cloud:spring-cloud-starter-security')
compile('org.springframework.cloud:spring-cloud-starter-oauth2')
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-jersey')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
之后启动项目访问:localhost:8080/oauth/authorize?client_id=client&response_type=code&redirect_uri=http://www.baidu.com
验证身份,用户名:user,密码:启动的日志中找到Using default security password,之后点授权
获得code码,在url中:https://www.baidu.com/?code=K52t0C