Documentation request: Oauth2 Resource Server servicing both REST and MVC endpoints
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 38/100
- Issue type
- Documentation
- Clarity
- Mostly clear
- Activity status
- Stale
- Domain
- authentication, backend, documentation
Research direction
Start with the YAML configuration and SecurityFilterChain examples in the issue, then compare them with the repository's current OAuth2 client and resource-server examples. Document a configuration that supports two providers, public and private MVC endpoints, and bearer-token APIs, and verify that the resulting examples cover each requested flow.
Written by the indexing model from the issue text.
Description
Overview: the current examples seem to work well when configuring EITHER a REST service OR a WebMVC endpoint using the Client flow. Most applications start as a full-stack flow; then quickly evolve to need to support iOS, Android, or external parties. Given this type of default behavior, I'd love to see some documentation on building a resource server (that can also do client activities) w/ the few additional steps necessary in terms of configuring the Security Filter Chain.
- Configure two authorization providers (e.g., Google and Github)
- Support rendering a public facing index "/" w/ a @Controller.
- Support rendering a private "/authenticated" @Controller
- Support APIs that authenticate using Bearer tokens (e.g., native app, or JS-based).
Starting points
server:
port: 8009
servlet:
session:
persistent: false
error:
whitelabel:
enabled: true
logging:
level:
org.springframework.security: TRACE
org.springframework.security.oauth2: TRACE
org.springframework.web: TRACE
org.springframework.web.reactive: TRACE
spring:
security:
oauth2:
client:
registration:
google:
clientId: SOME_VALUE.apps.googleusercontent.com
clientSecret: SOME_SECRET
redirectUri: "{baseUrl}/login/oauth2/code/{registrationId}"
scope:
- openid
- email
- profile
provider:
google:
authorizationUri: https://accounts.google.com/o/oauth2/v2/auth?access_type=offline&prompt=consent
tokenUri: https://oauth2.googleapis.com/token
userInfoUri: https://www.googleapis.com/oauth2/v3/userinfo
resource-server:
jwt:
issuer-uri: https://accounts.google.com/.well-known/openid-configuration
@Bean
SecurityFilterChain defaultSecurityFilterChain(final HttpSecurity http) throws Exception {
return http
.oauth2ResourceServer(OAuth2ResourceServerConfigurer::jwt)
.authorizeHttpRequests(auth -> {
auth.requestMatchers("/","/login**", "/webjars**","/assets**").permitAll();
auth.anyRequest().authenticated();
})
.httpBasic(Customizer.withDefaults())
.oauth2Login(oauth2 -> oauth2.loginPage(LOGIN_PAGE))
.formLogin().loginPage(LOGIN_PAGE).and()
.build();
}
Merging in something like this?
public SecurityFilterChain resourceServerOauthFilterChain(final HttpSecurity http) throws Exception {
http
.requestMatcher(request -> {
final String headerValue = request.getHeader("Authorization");
return headerValue != null && headerValue.startsWith("Bearer");
})
.authorizeRequests()
.anyRequest().authenticated()
.and()
.csrf().disable()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.oauth2ResourceServer().jwt(Customizer.withDefaults());
return http.build();
}
- Dominant language
- Java
- Stars
- 1.8k
- Forks
- 797
- Avg merge
- 3m
- Merged PRs (30d)
- 5
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from spring-projects/spring-security-samples
-
Difficulty 1/5 1-3 hours Newbie friendliness 86/100
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
spring-projects/spring-security-samples#353 · 1 comment ·
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
type: enhancement
spring-projects/spring-security-samples#347 · 2 comments · 1 assignee ·
All issues in spring-projects/spring-security-samples
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
infinispan/infinispan#18150 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
opensearch-project/k-NN#3597 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100