-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support OidcProviderClient injection and token revocation
- Loading branch information
1 parent
2ac009a
commit 849bbb2
Showing
25 changed files
with
455 additions
and
141 deletions.
There are no files selected for viewing
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
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
44 changes: 44 additions & 0 deletions
44
extensions/oidc/runtime/src/main/java/io/quarkus/oidc/OidcProviderClient.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,44 @@ | ||
package io.quarkus.oidc; | ||
|
||
import io.smallrye.mutiny.Uni; | ||
|
||
/** | ||
* Provides access to OIDC UserInfo, token introspection and revocation endpoints. | ||
*/ | ||
public interface OidcProviderClient { | ||
|
||
/** | ||
* Get UserInfo. | ||
* | ||
* @param accessToken access token which is required to access a UserInfo endpoint. | ||
* @return Uni<UserInfo> {@link UserInfo} | ||
*/ | ||
Uni<UserInfo> getUserInfo(String accessToken); | ||
|
||
/** | ||
* Introspect the access token. | ||
* | ||
* @param accessToken access oken which must be introspected. | ||
* @return Uni<TokenIntrospection> {@link TokenIntrospection} | ||
*/ | ||
Uni<TokenIntrospection> introspectAccessToken(String accessToken); | ||
|
||
/** | ||
* Revoke the access token. | ||
* | ||
* @param accessToken access token which needs to be revoked. | ||
* @return Uni<Boolean> true if the access token has been revoked or found already being invalidated, | ||
* false if the access token can not be currently revoked in which case a revocation request might be retried. | ||
*/ | ||
Uni<Boolean> revokeAccessToken(String accessToken); | ||
|
||
/** | ||
* Revoke the refresh token. | ||
* | ||
* @param refreshToken refresh token which needs to be revoked. | ||
* @return Uni<Boolean> true if the refresh token has been revoked or found already being invalidated, | ||
* false if the refresh token can not be currently revoked in which case a revocation request might be retried. | ||
*/ | ||
Uni<Boolean> revokeRefreshToken(String refreshToken); | ||
|
||
} |
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
55 changes: 55 additions & 0 deletions
55
...c/runtime/src/main/java/io/quarkus/oidc/runtime/OidcConfigurationAndProviderProducer.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,55 @@ | ||
package io.quarkus.oidc.runtime; | ||
|
||
import jakarta.enterprise.context.RequestScoped; | ||
import jakarta.enterprise.inject.Produces; | ||
import jakarta.inject.Inject; | ||
|
||
import io.quarkus.oidc.OIDCException; | ||
import io.quarkus.oidc.OidcConfigurationMetadata; | ||
import io.quarkus.oidc.OidcProviderClient; | ||
import io.quarkus.security.identity.SecurityIdentity; | ||
|
||
@RequestScoped | ||
public class OidcConfigurationAndProviderProducer { | ||
@Inject | ||
TenantConfigBean tenantConfig; | ||
@Inject | ||
SecurityIdentity identity; | ||
|
||
@Produces | ||
@RequestScoped | ||
OidcConfigurationMetadata produceMetadata() { | ||
OidcConfigurationMetadata configMetadata = OidcUtils.getAttribute(identity, OidcUtils.CONFIG_METADATA_ATTRIBUTE); | ||
|
||
if (configMetadata == null && tenantConfig.getDefaultTenant().oidcConfig().tenantEnabled()) { | ||
configMetadata = tenantConfig.getDefaultTenant().provider().getMetadata(); | ||
} | ||
if (configMetadata == null) { | ||
throw new OIDCException("OidcConfigurationMetadata can not be injected"); | ||
} | ||
return configMetadata; | ||
} | ||
|
||
@Produces | ||
@RequestScoped | ||
OidcProviderClient produceProviderClient() { | ||
OidcProviderClient client = null; | ||
String tenantId = OidcUtils.getAttribute(identity, OidcUtils.TENANT_ID_ATTRIBUTE); | ||
if (tenantId != null) { | ||
if (OidcUtils.DEFAULT_TENANT_ID.equals(tenantId)) { | ||
return tenantConfig.getDefaultTenant().getOidcProviderClient(); | ||
} | ||
TenantConfigContext context = tenantConfig.getStaticTenant(tenantId); | ||
if (context == null) { | ||
context = tenantConfig.getDynamicTenant(tenantId); | ||
} | ||
if (context != null) { | ||
client = context.getOidcProviderClient(); | ||
} | ||
} | ||
if (client == null) { | ||
throw new OIDCException("OidcProviderClient can not be injected"); | ||
} | ||
return client; | ||
} | ||
} |
31 changes: 0 additions & 31 deletions
31
...oidc/runtime/src/main/java/io/quarkus/oidc/runtime/OidcConfigurationMetadataProducer.java
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.