Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Sample RestTemplate Client with Spring Security Oauth2 with client_credentials flow

NotificationsYou must be signed in to change notification settings

gbzarelli/spring-security-oauth2-resttemplate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This sample works withSpring Security Oauth2 5 integrated in Spring Boot RestTemplate to makeclient requests with Oauth2 client credentials flow. The goal is manage request tokens and expirations time.

Caution!!

This lib inject the Spring Security context configurations, but, you can remove-it justadd the exclusions inspring-boot-starter-oauth2-client like that:

<dependency>    <groupId>org.springframework.boot</groupId>    <artifactId>spring-boot-starter-oauth2-client</artifactId>    <exclusions>        <exclusion>            <groupId>org.springframework.boot</groupId>            <artifactId>spring-boot-starter</artifactId>        </exclusion>        <exclusion>            <groupId>org.springframework.security</groupId>            <artifactId>spring-security-config</artifactId>        </exclusion>    </exclusions></dependency>

After that, just remove theSecurityConfiguration.java.

Oh no! I can't use Spring Security Oaut2 5, just 2.x versions, how to implement the client credentials flow?

If you can't upgrade, you can use theDEPRECATED way:(its implementation is easier to build a RestTemplate class)

// Build o OAuth2RestTemplate:final ClientCredentialsResourceDetails resourceDetails = new ClientCredentialsResourceDetails();resourceDetails.setAccessTokenUri("https://your.api.url.token.com/....");resourceDetails.setClientId("clientID");resourceDetails.setClientSecret("clientSecret");resourceDetails.setGrantType("client_credentials");final RestTemplate oauthClient = new OAuth2RestTemplate(resourceDetails);

My project uses Spring Boot version previous2.4.x version

Change thespring-boot-starter-oauth2-client dependency to:

<dependency><groupId>org.springframework.security</groupId><artifactId>spring-security-oauth2-client</artifactId><version>5.7.7</version></dependency><dependency><groupId>org.springframework.security</groupId><artifactId>spring-security-oauth2-core</artifactId><version>5.7.7</version></dependency>

References

About

Sample RestTemplate Client with Spring Security Oauth2 with client_credentials flow

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp