1) The OAuth 2.0 client credentials grant
The client credentials grant is used for when the client is requesting access for a resource that is owned or controlled by that client. There is no enduser in this scenario, unlike say the authorization code flow or implicit flow. The client simply calls the token endpoint of the authorization service using "client_credentials" for the "grant_type" parameter. In addition, the client must authenticate (e.g. by supplying client_id and client_secret parameters). The authorization service authenticates the client and then returns an access token.
2) Supporting the client credentials grant in Fediz OIDC
It's easy to support the client credentials grant in the Fediz OIDC service.
a) Add the ClientCredentialsGrantHandler
Firstly, the ClientCredentialsGrantHandler must be added to the list of grant handlers supported by the token service as follows:
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
<bean id="refreshTokenHandler" | |
class="org.apache.cxf.rs.security.oauth2.grants.refresh.RefreshTokenGrantHandler"> | |
<property name="dataProvider" ref="oauthProvider"/> | |
</bean> | |
<bean id="clientCredsHandler" | |
class="org.apache.cxf.rs.security.oauth2.grants.clientcred.ClientCredentialsGrantHandler"> | |
<property name="dataProvider" ref="oauthProvider"/> | |
</bean> | |
<util:list id="grantHandlers"> | |
<ref bean="refreshTokenHandler"/> | |
<ref bean="clientCredsHandler"/> | |
</util:list> | |
<bean id="accessTokenService" class="org.apache.cxf.rs.security.oauth2.services.AccessTokenService"> | |
<property name="dataProvider" ref="oauthProvider"/> | |
<property name="responseFilter" ref="idTokenFilter"/> | |
<property name="grantHandlers" ref="grantHandlers"/> | |
<property name="canSupportPublicClients" value="true"/> | |
</bean> |
The next step is to add a way of authenticating the client credentials. Fediz uses JAAS to make it easy for the deployer to plug in different JAAS LoginModules if required. To configure JAAS, you must specify the name of the JAAS LoginModule in the configuration of the OAuthDataProviderImpl:
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
<bean id="oauthProvider" | |
class="org.apache.cxf.fediz.service.oidc.OAuthDataProviderImpl" | |
init-method="init" destroy-method="close"> | |
<!-- List of accepted scopes --> | |
<property name="supportedScopes" ref="supportedScopes"/> | |
<!-- | |
List of scopes that the consent/authorization form should make | |
selected by default. For example, asking a user to do an extra click | |
to approve an "oidc" scope is a redundant operation because this scope | |
is required anyway. | |
--> | |
<property name="defaultScopes" ref="coreScopes"/> | |
<property name="invisibleToClientScopes" ref="invisibleToClientScopes"/> | |
<property name="contextName" value="sts"/> | |
</bean> |
For the normal OIDC flows, the Fediz OIDC uses a WS-Federation filter to redirect the browser to the Fediz IdP, where the end user is then ultimately authenticated by the STS that bundles with Fediz. Therefore it seems like a natural fit to re-use the STS to authenticate the client in the Fediz OIDC. Follow steps (a) and (b) above. Start the Fediz STS, but before starting the OIDC service, specify the "java.security.auth.login.config" system property to point to the following JAAS configuration file:
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
sts { | |
org.apache.cxf.ws.security.trust.STSLoginModule required | |
require.roles="true" | |
disable.on.behalf.of="true" | |
wsdl.location="https://localhost:${idp.https.port}/fediz-idp-sts/REALMA/STSServiceTransportUT?wsdl" | |
service.name="{http://docs.oasis-open.org/ws-sx/ws-trust/200512/}SecurityTokenService" | |
endpoint.name="{http://docs.oasis-open.org/ws-sx/ws-trust/200512/}TransportUT_Port"; | |
}; |
Hello Colm!
ReplyDeleteWhat is the URI of the 'util' namespace you used in this snippet?
Thanks,
Matteo
The snippet I was mentioning in the comment above (the xml is not rendered correctly...)
ReplyDelete<util:list id="grantHandlers">
<ref bean="refreshTokenHandler"/>
<ref bean="clientCredsHandler"/>
</util:list>
It is the standard spring util namespace:
ReplyDeletexmlns:util="http://www.springframework.org/schema/util"