Creating a Sign On with Open id connect

39
Create a Sign On with Open ID Connect Derek Binkley @DerekB_WI

Transcript of Creating a Sign On with Open id connect

Page 1: Creating a Sign On with Open id connect

Create a Sign On with Open ID Connect

Derek Binkley@DerekB_WI

Page 2: Creating a Sign On with Open id connect

★Lead Developer at National Conference of Bar Examiners★PHP and Java Developer★MySQL DBA★Father of Three★Home Pizza Chef★@DerekB_WI

Page 3: Creating a Sign On with Open id connect

Questions

• Yes! Please ask them.• During or at the end.

Page 4: Creating a Sign On with Open id connect

Why?

OpenID Connect is a new standardNot a lot of documentationBuilt upon Oauth 2.0 which is widespreadSign On across disconnected services

Page 5: Creating a Sign On with Open id connect

What is a sign on?

• Authentication (who are you?) • Authorization (what can you do?)

Page 6: Creating a Sign On with Open id connect

What is OpenID Connect?

A Simple Identity layer on top of OAuth 2.0Verify IdentityUser basic infoREST-likeMany client types

Page 7: Creating a Sign On with Open id connect

What is OAuth 2?

• A method of allowing authorized access to web resources without the need for usernames and passwords.

• More in Ben Ramsey's May 2016 PHP Architect article.

Page 8: Creating a Sign On with Open id connect

PHP Libraries

• Bshaffer’s oauth2-server-php library

Page 9: Creating a Sign On with Open id connect

Traditional MVC Application

Page 10: Creating a Sign On with Open id connect

Modern Distributed Architecture

Page 11: Creating a Sign On with Open id connect

Session State/Authentication

• Login maintained by connection between browser and Identity Provider

Page 12: Creating a Sign On with Open id connect

OpenID Steps1. Client prepares an Authentication Request containing the desired

request parameters. 2. Client sends the request to the Authorization Server. 3. Authorization Server Authenticates the End-User. 4. Authorization Server obtains End-User Consent/Authorization. 5. Authorization Server sends the End-User back to the Client with an

Authorization Code. 6. Client requests a response using the Authorization Code at the Token

Endpoint. 7. Client receives a response that contains an ID Token and Access Token

in the response body. 8. Client validates the ID token and retrieves the End-User's Subject

Identifier.

Page 13: Creating a Sign On with Open id connect

Setting up Your Auth Server

Page 14: Creating a Sign On with Open id connect

1. Client prepares an Authentication Request containing the desired request parameters.

• Client id• Client secret• Response Type• Scope• State

Page 15: Creating a Sign On with Open id connect

client_id/client_secret

• Specific to your application• Sets Up Return URL

Page 16: Creating a Sign On with Open id connect

Response_type

• Code• Id_token• Id_token token• Code id_token• Code token• Code id_token token

Page 17: Creating a Sign On with Open id connect

State

• Unique string saved by your app• Prevents a forged return call from Identity

Provider.

Page 18: Creating a Sign On with Open id connect

2. Client sends the request to the Authorization Server.

• Forward user to Auth Server URL• Have user post form to Auth Server

Page 19: Creating a Sign On with Open id connect

3. Authorization Server Authenticates the End-User.

• Implementation entirely up to you.• What? Isn’t this specification about

authentication?

Page 20: Creating a Sign On with Open id connect

Authentication Methods

• Something you know• Something you are• Something you have

Page 21: Creating a Sign On with Open id connect

4. Authorization Server obtains End-User Consent/Authorization.

• My app would like to access … Allow?• Optional if you are in control of all parts of the

chain.

Page 22: Creating a Sign On with Open id connect

5. Authorization Server sends the End-User back to the Client with an Authorization Code.

• Forward to client URL• Either receive error or code.• Trade code for token.

Page 23: Creating a Sign On with Open id connect

Auth Server Code

Page 24: Creating a Sign On with Open id connect
Page 25: Creating a Sign On with Open id connect

6. Client requests a response using the Authorization Code at the Token Endpoint.

• Your PHP app sends an http request back to the Identity Provider (OpenID server).

• Trades one time use code for token.

Page 26: Creating a Sign On with Open id connect

Client Code

Page 27: Creating a Sign On with Open id connect

7. Client receives a response that contains an ID Token and Access Token in the response body.

• Response back with ID token and access token• ID Token can be decrypted to ensure integrity

and details of session

Page 28: Creating a Sign On with Open id connect

Server Code

Page 29: Creating a Sign On with Open id connect

Client Code

Page 30: Creating a Sign On with Open id connect

8. Client validates the ID token and retrieves the End-User's Subject Identifier.

Page 31: Creating a Sign On with Open id connect

8. Client validates the ID token and retrieves the End-User's Subject Identifier.

Page 32: Creating a Sign On with Open id connect

Taking it further with session handling

• Sessions between App and Identity Provider don’t stay in sync.

• No way for App to check.

Page 33: Creating a Sign On with Open id connect

Modern Distributed Architecture

Page 34: Creating a Sign On with Open id connect

Logout Problem

• User logs out of Identity Provider then logins in as another user then returns to App.

• App still has access token for first login. • App won’t know immediately that token has

expired so could reveal one user’s data to another.

Page 35: Creating a Sign On with Open id connect

Embed an Iframe with Auth Server Connection

• Send message to iframe to get user’s login status.

• Handle response checking for ‘unchanged’

Page 36: Creating a Sign On with Open id connect

X-Frame-Options not enough

Page 37: Creating a Sign On with Open id connect

Content Security Policy in Apache Config

• Header set Content-Security-Policy "default-src * 'unsafe-inline' 'unsafe-eval'; frame-ancestors 'self' *.example.com"

Page 38: Creating a Sign On with Open id connect

Thanks

• Feedback at Meetup or Joind.in• https://joind.in/event/2016-madison-php-meetings