When and Why to Use OAuth2

Dave Syer, 2012
Twitter: @david_syer
Email: dsyer@vmware.com

(Securing REST-ful Web Services with OAuth2)

Agenda

Introduction

job-trends

What is a Lightweight Service?

What Are the Security Requirements

Identity and permissions:

HTTP Basic Authentication

Example:

    $ curl "https://$username:$password@myhost/resource"

So what's wrong with that?

User or Client Permissions

OAuth2

Centralizing account management and permissions:

Quick Introduction to OAuth2

A Client application, often web application, acts on behalf of a User, but with the User's approval

Common examples of Authorization Servers on the internet:

OAuth2 and the Lightweight Service

Example command line Client:

$ curl -H "Authorization: Bearer $TOKEN" https://myhost/resource

OAuth2 Key Features

UAA Bearer Tokens

Obtaining a Client Credentials Token

A client can act in its own right (not on behalf of a user):

$ curl "https://myclient:mysecret@uaa.cloudfoundry.com/oauth/tokens" 
    -d grant_type=client_credentials -d client_id=myclient

Result:

{
  access_token: FUYGKRWFG.jhdfgair7fylzshjg.o98q47tgh.fljgh,
  expires_in: 43200,
  client_id: myclient,
  scope: uaa.admin
}

Web Application Client

The Client wants to access a Resource on behalf of the User

oauth-web-client

Obtaining a User Token

A client can act on behalf of a user (e.g. authorization_code grant):

auth-code-flow

Authorization Code Grant Summary

  1. Authorization Server authenticates the User

  2. Client starts the authorization flow and obtain User's approval

  3. Authorization Server issues an authorization code (opaque one-time token)

  4. Client exchanges the authorization code for an access token.

Role of Client Application

Role of Resource Server

  1. Extract token from request and decode it
  2. Make access control decision
    • Scope
    • Audience
    • User account information (id, roles etc.)
    • Client information (id, roles etc.)
  3. Send 403 (FORBIDDEN) if token not sufficient

Role of the Authorization Server

  1. Grant tokens
  2. Interface for users to confirm that they authorize the Client to act on their behalf
  3. Authenticate users (/authorize)
  4. Authenticate clients (/token)

#1 and #4 are covered thoroughly by the spec; #2 and #3 not (for good reasons).

More on Scopes

Per the spec they are arbitrary strings. The Authorization Server and the Resource Servers agree on the content and meanings.

Examples:

Authorization Server has to decide whether to grant a token to a given client and user based on the requested scope (if any).

UAA Scopes

Special Mention for Vmc

The UAA authenticates requests from vmc in a special way:

$ curl https://uaa.cloudfoundry.com/oauth/authorize
    -d response_type=token -d client_id=vmc
    -d redirect_uri=https:uaa.cloudfoundry.com/redirect/vmc
    -d source=credentials
    -d username=$username -d password=$password

Result:

302 FOUND
...
Location: https://uaa.cloudfoundry.com/redirect/vmc#access_token=FUYGKRWFG.jhdfgair7fylzshjg.o98q47tgh.fljgh...  

Authentication and the Authorization Server

Cloud Foundry UAA Authorization Server

cf-uaa

Cloud Foundry UAA as a General Purpose Solution

UAA OAuth Implementation

UAA makes some explicit choices where the spec allows it, and also adds some useful features:

Alternatives to OAuth2

In Conclusion

#