-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: multitenancy for token exchange
- Loading branch information
1 parent
555e14b
commit b5e32b2
Showing
3 changed files
with
51 additions
and
31 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
...nd/src/main/java/ch/sbb/playgroundbackend/config/DynamicClientRegistrationRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package ch.sbb.playgroundbackend.config; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.security.core.context.SecurityContextHolder; | ||
import org.springframework.security.oauth2.client.registration.ClientRegistration; | ||
import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository; | ||
import org.springframework.security.oauth2.client.registration.ClientRegistrations; | ||
import org.springframework.security.oauth2.core.AuthorizationGrantType; | ||
import org.springframework.security.oauth2.jwt.Jwt; | ||
import org.springframework.security.oauth2.jwt.JwtClaimNames; | ||
|
||
@Configuration | ||
public class DynamicClientRegistrationRepository implements ClientRegistrationRepository { | ||
|
||
@Value("${auth.exchange.client-id}") | ||
private String clientId; | ||
|
||
@Value("${auth.exchange.client-secret}") | ||
private String clientSecret; | ||
|
||
@Value("${auth.exchange.scope}") | ||
private String scope; | ||
|
||
@Override | ||
public ClientRegistration findByRegistrationId(String registrationId) { | ||
String issuerUri = (String) ((Jwt) (SecurityContextHolder.getContext().getAuthentication().getPrincipal())).getClaims().get(JwtClaimNames.ISS); | ||
return ClientRegistrations.fromIssuerLocation(issuerUri) | ||
.authorizationGrantType(AuthorizationGrantType.JWT_BEARER) | ||
.clientId(clientId) | ||
.clientSecret(clientSecret) | ||
.scope(scope) | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters