File tree Expand file tree Collapse file tree 5 files changed +86
-0
lines changed
spring-5-security-oauth/src/main
java/com/baeldung/cognito Expand file tree Collapse file tree 5 files changed +86
-0
lines changed Original file line number Diff line number Diff line change 1+ package com .baeldung .cognito ;
2+
3+ import org .springframework .context .annotation .Configuration ;
4+ import org .springframework .context .annotation .PropertySource ;
5+ import org .springframework .web .servlet .config .annotation .ViewControllerRegistry ;
6+ import org .springframework .web .servlet .config .annotation .WebMvcConfigurer ;
7+
8+ @ Configuration
9+ @ PropertySource ("cognito/application_cognito.yml" )
10+ public class CognitoWebConfiguration implements WebMvcConfigurer {
11+
12+ @ Override
13+ public void addViewControllers (ViewControllerRegistry registry ) {
14+ registry .addViewController ("/" ).setViewName ("home" );
15+ }
16+ }
Original file line number Diff line number Diff line change 1+ package com .baeldung .cognito ;
2+
3+ import org .springframework .boot .SpringApplication ;
4+ import org .springframework .boot .autoconfigure .SpringBootApplication ;
5+ import org .springframework .context .annotation .PropertySource ;
6+
7+ @ SpringBootApplication
8+ @ PropertySource ("cognito/application_cognito.yml" )
9+ public class SpringCognitoApplication {
10+
11+ public static void main (String [] args ) {
12+ SpringApplication .run (SpringCognitoApplication .class , args );
13+ }
14+ }
Original file line number Diff line number Diff line change 1+ spring :
2+ security :
3+ oauth2 :
4+ client :
5+ registration :
6+ cognito :
7+ client-id : clientId
8+ client-secret : clientSecret
9+ scope : openid
10+ redirectUriTemplate : " http://localhost:8080/login/oauth2/code/cognito"
11+ clientName : cognito-client-name
12+ provider :
13+ cognito :
14+ issuerUri : https://cognito-idp.{region}.amazonaws.com/{poolId}
15+ usernameAttribute : cognito:username
Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html xmlns:th ="http://www.thymeleaf.org " xmlns:sec ="http://www.thymeleaf.org/extras/spring-security ">
3+ < head >
4+ < meta charset ="utf-8 ">
5+ < meta name ="viewport " content ="width=device-width, initial-scale=1 ">
6+ < title > OAuth2 Cognito Demo</ title >
7+
8+ < link rel ="stylesheet " href ="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.4/css/bulma.min.css ">
9+ < link rel ="stylesheet " th:href ="@{/cognito/style.css} ">
10+ </ head >
11+ < body >
12+ < section class ="section ">
13+ < div class ="container has-text-centered ">
14+ < div >
15+ < h1 class ="title "> OAuth2 Spring Security Cognito Demo</ h1 >
16+
17+ < div sec:authorize ="isAuthenticated() ">
18+ < div class ="box ">
19+ Hello, < strong th:text ="${#authentication.name} "> </ strong > !
20+ </ div >
21+ </ div >
22+
23+ < div sec:authorize ="isAnonymous() ">
24+ < div class ="box ">
25+ < a class ="button login is-primary " th:href ="@{/oauth2/authorization/cognito} "> Log in with Amazon Cognito</ a >
26+ </ div >
27+ </ div >
28+ </ div >
29+ </ div >
30+ </ section >
31+ </ body >
32+ </ html >
Original file line number Diff line number Diff line change 1+ .login {
2+ background-color : # 7289da ;
3+ color : # fff ;
4+ }
5+
6+ .login : hover {
7+ background-color : # 697ec4 ;
8+ color : # fff ;
9+ }
You can’t perform that action at this time.
0 commit comments