h1. CXF OAuth 1.0 extension

CXF OAuth 1.0 extension has been build during Google Summer of Code 2010 programme. It implements specification: [The OAuth 1.0 protocol (RFC 5849)|http://tools.ietf.org/html/rfc5849]  and allows CXF users to build OAuth server

and perform OAuth 1.0 authorization on their JAXRS services in a easy manner, by hiding complex OAuth flow. 

h3. {color:#003366}{*}Downloading CXF OAuth 1.0 module{*}{color}

{TBD}

h3. OAuth Server basic configuration

CXF, provides implementation for three endpoints from OAuth 1.0 specification:
* *Temporary Credentials Endpoint*
* *Authorization Endpoint*
* *Token Credentials Endpoint*

which are usual JAX-RS resources. They allow client application to receive access token from the server required to access resources at that server.

Configuration is exatcly this same as for every JAX-RS service:
{code}
<!-- Publish OAuth endpoints-->
    <jaxrs:server id="oauthServer" address="/oauth/">
        <jaxrs:serviceBeans>
            <ref bean="oauthServices"/>
        </jaxrs:serviceBeans>
        <jaxrs:providers>
            <ref bean="dispatchProvider"/>
        </jaxrs:providers>
    </jaxrs:server>

    <!--Definitions of OAuth module endpoints-->
    <bean id="oauthServices"
          class="org.apache.cxf.auth.oauth.endpoints.OAuthDefaultServices">
        <property name="displayVerifierURL" value="http://www.example.com/app/displayVerifier"/>
    </bean>

    <!--Redirects from Resource Owner Authorization Endpoint to sign in page-->
    <bean id="dispatchProvider">
        <property name="resourcePath" value="/oAuthLogin.jsp"/>
    </bean>
{code}OAuth Server requires to save and read an OAuth data (OAuth tokens, oauth_verifier, client identifier ...)&nbsp;from the&nbsp;persistence&nbsp;storage specific for the&nbsp;particural web application.&nbsp;

To make that transparent to the developers, CXF uses:

{code}
org.apache.cxf.auth.oauth.provider.OAuthDataProvider
{code}
interface as an integration point between llibrary and the application. There is provided sample&nbsp;implementation of that interface that manages data stored in the memory:


{code}
org.apache.cxf.auth.oauth.provider.MemoryOauthDataProvider
{code}

that is located in core OAuth module and&nbsp;

{code}
org.apache.cxf.auth.oauth.demo.server.oauth.SampleOAuthDataProvider
{code}
in OAuth demo server module.

h2. *OAuth Endpoints explained*

{color:#003366}*[Temporary Credentials|http://tools.ietf.org/html/rfc5849#section-2.1]*{color}

Client sends oauth required parameters in order to receive temporary request token. CXF handles request, validates it,&nbsp;reads required information about the client and

save state(request token returned to the client in the response) required in the next OAuth request. CXF returns OAuth 1.0a specification compliant response.

h5. [Resource Owner Authorization|http://tools.ietf.org/html/rfc5849#section-2.2]

To assure more flexible authorization and access control to the server resources there were added two custom parameters:
* *x_oauth_scope* \- specifies comma separated server uri's to which client wants to have access
* *x_oauth_permission* \- specifies comma separated list of permissions to x_oauth_scope uri's which client wants to have

i.e.:
After granting permissions by the user to server resources, CXF saves this data that will be required in later access control evaluation, generates oauth_verifier&nbsp;and returns it to the client. !confirmation.png|border=1!

*Examplar screen where server user allows/denies access for a third party application*

Location of above confirmation screen can be configured by registering dispatch provider as shown in&nbsp;OAuth Server basic configuration.CXF return OAuth compliant errors in case of wrong client requests.&nbsp;


h5. [Token Credentials|http://tools.ietf.org/html/rfc5849#section-2.3]

Token Credentials Endpoint
Client sends request to the Authorization Server in order to exchange previously received oauth_verifier on access token. Similarly in this step CXF handles request and return suitable response.
If the request is correct client receives an OAuth access token.
Access token give the rights to the user on the particular client to access previously authorized scopes with associated permissions.
Client need to attach access token with every request to oauth protected resource.