#META_LECTURE#: #TITLE#

Modified: #LAST_MODIFIED#
Humla v#HUMLA_VERSION#
Security Concepts

Web Service Security Concepts

Data on the Web

Authentication and Authorization

Transport Level Security

Overview

TLS Handshake Protocol

TLS and Proxy Servers

JSON Web Token

Overview

Use of JWT

JWT Structure

JWT Structure (Cont.)

How to use JWT

Expiration and revocation

OAuth 2.0

Motivation

When there is no OAuth

OAuth 2.0 Protocol

Terminology

Client-side Web Apps

Client-side Web Apps

  • Simplified version of OAuth 2.0 protocol
    • JavaScript/AJAX apps running in a browser
    • Apps that cannot easily "remember" app state
    • limited number of interactions
  • Architecture
    • User-agent processes a javascript/HTML code from the client
    • No need of authorization code
  • Basic Steps
    • A client redirects a user agent to the authorization endpoint
    • A resource owner grants an access to the client
      • or he/she rejects the request
    • Authorization server provides an access_token to the client
    • Client access the resource with the access_token
    • When the token expires, client requests a new token

Demo – List of Contacts

  • Display your Google contacts
    • this demo requests authorization from you to access your Google contacts using client-side OAuth 2.0 protocol and then displays the contacts below. In order to transfer access_token from authorization window, it stores the access_token in a cookie.
    • access_token
    • Show contacts or revoke access

Client-side Web Apps Protocol

Redirection – Step 1

  • Methods and Parameters
    • Methods: GET or POST
    • example authorazation endpoint url (Google): https://accounts.google.com/o/oauth2/auth
    • query string parameters or application/x-www-form-urlencoded
      • client_id – id of the client that was previously registered
      • redirect_uri – an URI that auth. server will redirect to when user grants/rejects
      • scope – string identifying resources/services to be accessed
      • response_type – type of the response (token or code)
      • state (optional) – state between request and redirect
    • Example
    • 							https://accounts.google.com/o/oauth2/auth?
      							client_id=621535099260.apps.googleusercontent.com&
      							redirect_uri=http://w20.vitvar.com/examples/oauth/callback.html&
      							scope=https://www.google.com/m8/feeds&
      							response_type=token

Callback – steps 4 and 5

  • Resource owner grants the access
    • authorization server calls back redirect_uri
    • client parses URL in JavaScript (Step 5)
      • extracts access_token and expires_in (by using window.location.hash)
    • Example:
    • 							https://w20.vitvar.com/examples/oauth/callback.html#
      							access_token=1/QbZfgDNsnd&
      							expires_in=4301
  • Resource owner rejects the access
    • authorization server calls back redirect_uri with query string parameter error=access_denied
    • Example:
    • 								hhttp://w20.vitvar.com/examples/oauth/callback.html?
      								error=access_denied

Accessing Resources – Step 6

  • Request
    • client can access resources defined by scope
    • resources' URIs defined in a particular documentation
    • Example Google Contacts
      • to access all users' contacts stored in Google
      • scope is https://www.google.com/m8/feeds
    • Query string parameter oauth_token
    • 							curl https://www.google.com/m8/feeds/contacts/default/full?
      								oauth_token=1/dERFd34Sf
    • HTTP Header Authorization
    • 								curl -H "Authorization: OAuth 1/dERFd34Sf"
      									https://www.google.com/m8/feeds/contacts/default/full
    • The client can do any allowed operations on the resource
  • Response
    • Success – 200 OK
    • Error – 401 Unauthorized when token expires or the client hasn't performed the authorization request.

Cross-Origin Resource Sharing

Example Application Registration

Google API Console
Server-side Web Apps

Server-side Web Apps

  • Additional interactions
    • server-side code (any language), the app can maintain the state
    • additional interactions, authorization code
  • Architecture
    • Client at a server requests, remembers and refresh access tokens
  • Basic steps
    • Client redirects user agent to the authorization endpoint
    • Resource owner grants access to the client or rejects the request
    • Authorization server provides authorization code to the client
    • Client requests access and refresh tokens from the auth. server
    • Client access the resource with the access token
    • When the token expires, client refreshes a token with refresh token
  • Advantages
    • Access tokens not visible to clients, they are stored at the server
    • more secure, clients need to authenticate before they can get tokens

Server-side Web Apps Protocol

Redirection – Step 1

  • Methods and Parameters
    • same as for client-side app, except response_type must be code
  • Example
  • 							https://accounts.google.com/o/oauth2/auth?
    							client_id=621535099260.apps.googleusercontent.com&
    							redirect_uri=http://w20.vitvar.com/examples/oauth/callback.html&
    							scope=https://www.google.com/m8/feeds&
    							response_type=code

Callback + Access Token Request – steps 4, 5

  • Callback
    • authorization server calls back redirect_uri
    • client gets the code and requests access_token
    • example (resource owner grants access):
      http://w20.vitvar.com/examples/oauth/callback.html?code=4/P7...
    • when user rejects → same as client-side access
  • Access token request
    • POST request to token endpoint
      → example Google token endpoint: https://accounts.google.com/o/oauth2/token
    • 							POST /o/oauth2/token HTTP/1.1
      							Host: accounts.google.com
      							Content-Type: application/x-www-form-urlencoded
      
      							code=4/P7q7W91a-oMsCeLvIaQm6bTrgtp6&
      							client_id=621535099260.apps.googleusercontent.com&
      							client_secret=XTHhXh1S2UggvyWGwDk1EjXB&
      							redirect_uri=http://w20.vitvar.com/examples/oauth/callback.html&
      							grant_type=authorization_code

Access Token (cont.)

  • Access token response
    • Token endpoint responds with access_token and refresh_token
    • 							{ "access_token"   : "1/fFAGRNJru1FTz70BzhT3Zg",
      							  "expires_in"     : 3920,
      							  "refresh_token"  : "1/6BMfW9j53gdGImsixUH6kU5RsR4zwI9lUVX-tqf8JXQ" }
  • Refreshing a token
    • POST request to the token endpoint with grant_type=refresh_token and the previously obtained value of refresh_token
    • 							POST /o/oauth2/token HTTP/1.1
      							Host: accounts.google.com
      							Content-Type: application/x-www-form-urlencoded
      
      							client_id=21302922996.apps.googleusercontent.com&
      							client_secret=XTHhXh1SlUNgvyWGwDk1EjXB&
      							refresh_token=1/6BMfW9j53gdGImsixUH6kU5RsR4zwI9lUVX-tqf8JXQ&
      							grant_type=refresh_token
  • Accessing a resource is the same as in the client-side app
OpenID

OpenID Protocol

Interaction Sequence

Login Authentication Request – Step 5

Login Authentication Response – Step 8

OpenID Connect

OpenID Connect (OIDC)

  • Simple identity layer on top of the OAuth 2.0 protocol
    • Authorization Server to verify identity of users
    • Clients can obtain basic profile information about users
  • OIDC vs OpenID
    • OIDC does many of the same tasks as OpenID 2.0
    • API-friendly
      • can be used by native and mobile applications
    • Robust signing and encryption mechanisms
    • Native integration with OAuth 2.0.
  • Defined by OpenID open standard

Interaction sequence