Technologies used:
1. Spring Boot 2.2.6.RELEASE
2. Maven
3. OAuth2
4. Intellij IDEA Community
5. Spring Tools Suite (STS) 4
6. MySql
7. Postman
Code on GitHub:
https://github.com/HenryXiloj/Kotlin-OAuth2-SpringBoot2-JPA
Steps:
Create table on MySql:
CREATE TABLE `users`
(
`id` INT(11) NOT NULL auto_increment,
`username` VARCHAR(255) NOT NULL,
`password` VARCHAR(255) NOT NULL,
`created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP() on
UPDATE CURRENT_TIMESTAMP(),
PRIMARY KEY (`id`)
)
I saved the password field with Security - Password Enconding (org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder)
INSERT INTO users
VALUES (1,
'henry',
'$2a$04$I9Q2sDc4QGGg5WNTLmsz0.fvGv3OjoZyj81PrSFyGOqMphqfS2qKu');
IntelliJ: File -> open --> choose folder backend
Change the configuration on file application.yml
Run project from IntelliJ :
View -> Tool Windows -> Maven -> Execute Maven Goal-> mvn install
Run project backend.jar with java -jar backend.jar, in the file configuration you can define context for application, i define context --> backend and port 9000.
Credencials for test:
Test: Get token
Test: Error when you try to access ws, you need to add access_token
Add access_token -> url?access_token=your_token.
References:
https://www.devglan.com/spring-security/spring-boot-security-oauth2-example