добавлен пример для GitHub
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
package example.oauth2.github;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class ApplicationGithub {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ApplicationGithub.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package example.oauth2.github.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@Configuration
|
||||
public class MvcConfig implements WebMvcConfigurer {
|
||||
|
||||
@Override
|
||||
public void addViewControllers(ViewControllerRegistry registry) {
|
||||
registry.addViewController("/").setViewName("index");
|
||||
registry.addViewController("/secret").setViewName("secret");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package example.oauth2.github.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||
|
||||
@EnableWebSecurity
|
||||
@Configuration
|
||||
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
|
||||
@Override
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
//@formatter:off
|
||||
http
|
||||
.authorizeRequests()
|
||||
.antMatchers("/").permitAll() //Доступ разрешен всем пользователей
|
||||
.anyRequest().authenticated() //Все остальные страницы требуют аутентификации
|
||||
.and()
|
||||
.oauth2Login()
|
||||
;
|
||||
//@formatter:on
|
||||
}
|
||||
}
|
||||
14
github/src/main/resources/application.yml
Normal file
14
github/src/main/resources/application.yml
Normal file
@@ -0,0 +1,14 @@
|
||||
server:
|
||||
address: 127.0.0.1
|
||||
port: 8080
|
||||
|
||||
debug: false
|
||||
|
||||
spring:
|
||||
security:
|
||||
oauth2:
|
||||
client:
|
||||
registration:
|
||||
github:
|
||||
client-id: f9bbf16cc3a93663282f
|
||||
client-secret: 16f203668e25bfe44513d2a7b4925d62bb100783
|
||||
18
github/src/main/resources/templates/index.html
Normal file
18
github/src/main/resources/templates/index.html
Normal file
@@ -0,0 +1,18 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="ru"
|
||||
xmlns="http://www.w3.org/1999/xhtml"
|
||||
xmlns:th="https://www.thymeleaf.org">
|
||||
<head>
|
||||
<title>GitHub OAuth2 Example</title>
|
||||
<link rel="icon" href="data:;base64,=">
|
||||
</head>
|
||||
<body>
|
||||
<h1>GitHub OAuth2 Example</h1>
|
||||
<hr>
|
||||
<p>
|
||||
Home public page<br>
|
||||
---> <a th:href="@{/secret}">Secret Page</a> <---<br>
|
||||
[ <a th:href="@{/oauth2/authorization/github}">Login GitHub</a> ]
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
12
github/src/main/resources/templates/secret.html
Normal file
12
github/src/main/resources/templates/secret.html
Normal file
@@ -0,0 +1,12 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="ru">
|
||||
<head>
|
||||
<title>GitHub OAuth2 Example</title>
|
||||
<link rel="icon" href="data:;base64,=">
|
||||
</head>
|
||||
<body>
|
||||
<h1>GitHub OAuth2 Example</h1>
|
||||
<hr>
|
||||
<p style="color: red">[TOP SECRET PAGE]</p>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user