Upgrade to Pro — share decks privately, control downloads, hide ads and more …

OAuth 2 for Me and You - 2022 Edition

OAuth 2 for Me and You - 2022 Edition

This session was given at the Adobe ColdFusion Summit 2022 in Las Vegas, Monday October 3rd, 2022.

It covered the OAuth 2 protocol, what it means to be a consumer or provider, and how to navigate the handshake communications between the service. At the end of this session all attendees walked taller, safe in the fact that they understand OAuth 2, how to use it, and what it all means.

Matt Gifford

October 07, 2022
Tweet

More Decks by Matt Gifford

Other Decks in Technology

Transcript

  1. OAUTH 2 FOR ME AND YOU
    Matt Gi
    ff
    ord - Adobe ColdFusion Summit 2022

    View full-size slide

  2. ABOUT ME
    @coldfumonkeh
    app developer / software architect
    writer

    View full-size slide

  3. THE SETLIST
    ➤ OAuth?


    ➤ Important De
    fi
    nitions


    ➤ How to be a consumer


    ➤ The Authorization Code Flow


    ➤ Useful Tools

    View full-size slide

  4. THE SCENARIO

    View full-size slide

  5. THE SCENARIO
    I am writing a web-based
    application for lovers of music.


    I want to access data from
    third-party services to enhance
    my application.

    View full-size slide

  6. THE SCENARIO
    I am going to use Spotify to
    build a fun project that can
    generate dynamic playlists for
    the authenticating user.

    View full-size slide

  7. THE SCENARIO
    My application will need to log
    into Spotify on behalf of my
    users to access their account
    information and have write
    access to their playlists.

    View full-size slide

  8. THE SCENARIO

    View full-size slide

  9. WHAT IS OAUTH?

    View full-size slide

  10. WHAT IS OAUTH?

    View full-size slide

  11. A delegation framework to allow
    secure authorization in a simple
    and standard method from web,
    mobile and desktop applications
    WHAT IS OAUTH?

    View full-size slide

  12. A delegation framework to allow
    secure authorization in a simple
    and standard method from web,
    mobile and desktop applications
    WHAT IS OAUTH?

    View full-size slide

  13. A BRIEF HISTORY

    View full-size slide

  14. A BRIEF HISTORY
    2006 Twitter Chief Architect looked for a better authentication method - no passwords
    2007 OpenID development group (and contributors) came up with the OAuth 1 first draft
    2007 7 updated drafts by the end of the year
    2009 OAuth 2.0 spec was started
    “.. to clear up many of the aspects of OAuth 1 that were difficult or confusing.”
    2012 OAuth 2.0 core spec was published
    There were
    MANY more revisions to the draft

    View full-size slide

  15. ROLES
    Resource Owner
    (The User)

    View full-size slide

  16. ROLES
    Resource Owner
    (The User)
    The Client
    (The App)

    View full-size slide

  17. ROLES
    The Client
    (The App)
    Resource Owner
    (The User)
    Resource Server

    View full-size slide

  18. ROLES
    The Client
    (The App)
    Resource Owner
    (The User)
    Resource Server
    Authorization Server

    View full-size slide

  19. ROLES
    The Client
    (The App)
    Resource Owner
    (The User)
    Resource Server Authorization Server

    View full-size slide

  20. TOKENS
    ACCESS TOKEN

    View full-size slide

  21. TOKENS
    REFRESH TOKEN

    View full-size slide

  22. BEING A
    CONSUMER

    View full-size slide

  23. REGISTERING YOUR APP

    View full-size slide

  24. REGISTERING YOUR APP

    View full-size slide

  25. REGISTERING YOUR APP

    View full-size slide

  26. REGISTERING YOUR APP

    View full-size slide

  27. REGISTERING YOUR APP

    View full-size slide

  28. REGISTERING YOUR APP

    View full-size slide

  29. REGISTERING YOUR APP

    View full-size slide

  30. REGISTERING YOUR APP

    View full-size slide

  31. REGISTERING YOUR APP

    View full-size slide

  32. THE WORKFLOW

    View full-size slide

  33. My


    Application Spotify
    Authorization


    Server
    Spotify
    Resource


    Server
    THE WORKFLOW
    https://accounts.spotify.com/authorize?
    client_id=0170ed62bfad4dcc90bd5b057787790e&code_challenge=1assIs_OhqosI
    koRWb8MopQ9hqHN9gj8HF4HXd06U2U&code_challenge_method=S256&state=A
    7CC19EA-D207-414D-9C6C6083A5E1237D&redirect_uri=http://
    myapp.local:10539/callback/&scope=playlist-modify-public%20playlist-modify-
    public%20user-read-email%20user-follow-modify&response_type=code

    View full-size slide

  34. My


    Application Spotify
    Authorization


    Server
    Spotify
    Resource


    Server
    User Authorization Request
    THE WORKFLOW

    View full-size slide

  35. My


    Application Spotify
    Authorization


    Server
    Spotify
    Resource


    Server
    User Authorization Request
    THE WORKFLOW
    LINK HREF
    https://accounts.spotify.com/authorize

    View full-size slide

  36. My


    Application Spotify
    Authorization


    Server
    Spotify
    Resource


    Server
    User Authorization Request
    THE WORKFLOW
    https://accounts.spotify.com/authorize?


    client_id=0170ed62bfad4dcc90bd5b057787790e
    LINK HREF

    View full-size slide

  37. My


    Application Spotify
    Authorization


    Server
    Spotify
    Resource


    Server
    User Authorization Request
    https://accounts.spotify.com/authorize?


    client_id=0170ed62bfad4dcc90bd5b057787790e


    &response_type=code
    LINK HREF
    THE WORKFLOW

    View full-size slide

  38. My


    Application Spotify
    Authorization


    Server
    Spotify
    Resource


    Server
    User Authorization Request
    https://accounts.spotify.com/authorize?


    client_id=0170ed62bfad4dcc90bd5b057787790e


    &response_type=code


    &redirect_uri=https://myapp.local:10538/callback
    LINK HREF
    THE WORKFLOW

    View full-size slide

  39. My


    Application Spotify
    Authorization


    Server
    Spotify
    Resource


    Server
    User Authorization Request
    https://accounts.spotify.com/authorize?


    client_id=0170ed62bfad4dcc90bd5b057787790e


    &response_type=code


    &redirect_uri=https://myapp.local:10538/callback


    &scope=playlist-modify-public user-read-email


    LINK HREF
    THE WORKFLOW

    View full-size slide

  40. My


    Application Spotify
    Authorization


    Server
    Spotify
    Resource


    Server
    User Authorization Request
    https://accounts.spotify.com/authorize?


    client_id=0170ed62bfad4dcc90bd5b057787790e


    &response_type=code


    &redirect_uri=https://myapp.local:10538/callback


    &scope=playlist-modify-public user-read-email


    &state=9DC18EB2-3B79-4E05-904BD9E6590267C2
    LINK HREF
    THE WORKFLOW

    View full-size slide

  41. My


    Application
    Spotify
    Do you give permission for
    My Application to


    access your basic profile
    information?
    No
    Yes
    Spotify
    Authorization


    Server
    Spotify
    Resource


    Server
    User Authorization Request
    THE WORKFLOW

    View full-size slide

  42. User Authorization Request
    Authorization Code Grant
    My


    Application Spotify
    Authorization


    Server
    Spotify
    Resource


    Server
    https://myapp.local:10538/callback?code=AUTHORIZATION_CODE
    https://myapp.local:10538/callback?error=XXX
    THE WORKFLOW

    View full-size slide

  43. User Authorization Request
    Authorization Code Grant
    My


    Application Spotify
    Authorization


    Server
    Spotify
    Resource


    Server
    THE WORKFLOW

    View full-size slide

  44. 10 mins
    30-60


    secs
    THE WORKFLOW

    View full-size slide

  45. THE WORKFLOW

    View full-size slide

  46. My


    Application Spotify
    Authorization


    Server
    Spotify
    Resource


    Server
    User Authorization Request
    THE WORKFLOW
    Authorization Code Grant
    Access Token Request

    View full-size slide

  47. My


    Application Spotify
    Authorization


    Server
    Spotify
    Resource


    Server
    User Authorization Request
    REQUESTING AN ACCESS TOKEN
    Authorization Code Grant
    Access Token Request

    View full-size slide

  48. My


    Application Spotify
    Authorization


    Server
    Spotify
    Resource


    Server
    User Authorization Request
    REQUESTING AN ACCESS TOKEN
    Authorization Code Grant
    Access Token Request
    POST https://accounts.spotify.com/token

    View full-size slide

  49. My


    Application Spotify
    Authorization


    Server
    Spotify
    Resource


    Server
    User Authorization Request
    REQUESTING AN ACCESS TOKEN
    Authorization Code Grant
    Access Token Request
    POST
    grant_type=authorization_code
    https://accounts.spotify.com/token

    View full-size slide

  50. My


    Application Spotify
    Authorization


    Server
    Spotify
    Resource


    Server
    User Authorization Request
    REQUESTING AN ACCESS TOKEN
    Authorization Code Grant
    Access Token Request
    POST
    grant_type=authorization_code


    code=33160
    https://accounts.spotify.com/token

    View full-size slide

  51. My


    Application Spotify
    Authorization


    Server
    Spotify
    Resource


    Server
    User Authorization Request
    REQUESTING AN ACCESS TOKEN
    Authorization Code Grant
    Access Token Request
    POST
    grant_type=authorization_code


    code=33160


    redirect_uri=https://myapp.local:10538/callback
    https://accounts.spotify.com/token

    View full-size slide

  52. My


    Application Spotify
    Authorization


    Server
    Spotify
    Resource


    Server
    User Authorization Request
    REQUESTING AN ACCESS TOKEN
    Authorization Code Grant
    Access Token Request
    POST
    grant_type=authorization_code


    code=33160


    redirect_uri=https://myapp.local:10538/callback


    client_id=a3dd5f928fb04a1f8b5f7bdd3dbd3010
    https://accounts.spotify.com/token

    View full-size slide

  53. My


    Application Spotify
    Authorization


    Server
    Spotify
    Resource


    Server
    User Authorization Request
    REQUESTING AN ACCESS TOKEN
    Authorization Code Grant
    Access Token Request
    POST
    grant_type=authorization_code


    code=33160


    redirect_uri=https://myapp.local:10538/callback


    client_id=a3dd5f928fb04a1f8b5f7bdd3dbd3010


    client_secret=e6b218b3a4cb46d8a11578b8a60f55fb
    https://accounts.spotify.com/token

    View full-size slide

  54. My


    Application Spotify
    Authorization


    Server
    Spotify
    Resource


    Server
    User Authorization Request
    RECEIVING THE ACCESS TOKEN
    Authorization Code Grant
    Access Token Request
    Access Token Grant

    View full-size slide

  55. My


    Application Spotify
    Authorization


    Server
    Spotify
    Resource


    Server
    User Authorization Request
    RECEIVING THE ACCESS TOKEN
    Authorization Code Grant
    Access Token Request
    Access Token Grant

    View full-size slide

  56. User Authorization Request
    Authorization Code Grant
    Access Token Request
    Access Token Grant
    Authenticated API Request
    Protected Resources
    My


    Application Spotify
    Authorization


    Server
    Spotify
    Resource


    Server
    ACCESSING RESOURCES

    View full-size slide

  57. User Authorization Request
    Authorization Code Grant
    Access Token Request
    Access Token Grant
    Authenticated API Request
    Protected Resources
    My


    Application Spotify
    Authorization


    Server
    Spotify
    Resource


    Server
    Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9
    ACCESSING RESOURCES

    View full-size slide

  58. ACCESSING RESOURCES

    View full-size slide

  59. User Authorization Request
    Authorization Code Grant
    Access Token Request
    Access Token Grant
    Authenticated API Request
    Protected Resources
    My


    Application Spotify
    Authorization


    Server
    Spotify
    Resource


    Server
    ACCESSING RESOURCES

    View full-size slide

  60. REFRESH TOKENS

    View full-size slide

  61. REFRESH TOKENS

    View full-size slide

  62. REFRESHING AN ACCESS TOKEN
    POST https://accounts.spotify.com/token

    View full-size slide

  63. REFRESHING AN ACCESS TOKEN
    POST
    grant_type=refresh_token
    https://accounts.spotify.com/token

    View full-size slide

  64. REFRESHING AN ACCESS TOKEN
    POST
    grant_type=refresh_token


    refresh_token=SflKxwRJSMeKKF2QT4fwpM…
    https://accounts.spotify.com/token

    View full-size slide

  65. REFRESHING AN ACCESS TOKEN
    POST
    grant_type=refresh_token


    refresh_token=SflKxwRJSMeKKF2QT4fwpM…


    client_id=a3dd5f928fb04a1f8b5f7bdd3dbd3010
    https://accounts.spotify.com/token

    View full-size slide

  66. REFRESHING AN ACCESS TOKEN
    POST
    grant_type=refresh_token


    refresh_token=SflKxwRJSMeKKF2QT4fwpM…


    client_id=a3dd5f928fb04a1f8b5f7bdd3dbd3010


    client_secret=e6b218b3a4cb46d8a11578b8a60f55fb
    https://accounts.spotify.com/token

    View full-size slide

  67. REFRESHING AN ACCESS TOKEN

    View full-size slide

  68. REFRESHING AN ACCESS TOKEN

    View full-size slide

  69. USEFUL TOOLS #1

    View full-size slide

  70. USEFUL TOOLS #1

    View full-size slide

  71. USEFUL TOOLS #1

    View full-size slide

  72. USEFUL TOOLS #1

    View full-size slide

  73. USEFUL TOOLS #1

    View full-size slide

  74. USEFUL TOOLS #1

    View full-size slide

  75. USEFUL TOOLS #1

    View full-size slide

  76. PKCE
    (Proof Key for Code Exchange)

    View full-size slide

  77. PKCE
    A-Z a-z 0-9 -._~
    1XxTnj2kNC2Szytqp7WDck3jVUD61nu5KwtQQJBIL_HIH6R3
    Code Veri
    fi
    er

    View full-size slide

  78. PKCE
    base64url( sha256( code_veri
    fi
    er ) )
    tZSYs8eBdSGBJpDo3wOPaj729KNWRMnkbG1moPcwB2Q
    Code Challenge

    View full-size slide

  79. My


    Application Spotify
    Authorization


    Server
    Spotify
    Resource


    Server
    User Authorization Request
    PKCE
    https://accounts.spotify.com/authorize?


    client_id=0170ed62bfad4dcc90bd5b057787790e


    &response_type=code


    &redirect_uri=https://myapp.local:10538/callback


    &scope=playlist-modify-public user-read-email


    &state=9DC18EB2-3B79-4E05-904BD9E6590267C2

    View full-size slide

  80. My


    Application Spotify
    Authorization


    Server
    Spotify
    Resource


    Server
    User Authorization Request
    PKCE
    https://accounts.spotify.com/authorize?


    client_id=0170ed62bfad4dcc90bd5b057787790e


    &response_type=code


    &redirect_uri=https://myapp.local:10538/callback


    &scope=playlist-modify-public user-read-email


    &state=9DC18EB2-3B79-4E05-904BD9E6590267C2


    &code_challenge=tZSYs8eBdSGBJpDo3wOPaj729KNWR


    &code_challenge_method=S256

    View full-size slide

  81. My


    Application Spotify
    Authorization


    Server
    Spotify
    Resource


    Server
    User Authorization Request
    PKCE
    code_challenge=tZSYs8eBdSGBJpDo3wOPaj729KNWR


    code_challenge_method=S256

    View full-size slide

  82. My


    Application Spotify
    Authorization


    Server
    Spotify
    Resource


    Server
    User Authorization Request
    PKCE
    POST
    grant_type=authorization_code


    code=10538


    redirect_uri=https://myapp.local:10538/callback


    client_id=a3dd5f928fb04a1f8b5f7bdd3dbd3010


    client_secret=e6b218b3a4cb46d8a11578b8a60f55fb
    https://accounts.spotify.com/token
    code_verifier=1XxTnj2kNC2Szytqp7WDck3jVUD61nu5KwtQQJBIL_HIH6R3

    View full-size slide

  83. My


    Application Spotify
    Authorization


    Server
    Spotify
    Resource


    Server
    User Authorization Request
    PKCE
    base64url( sha256( code_verifier ) ) = code_challenge
    ?

    View full-size slide

  84. USEFUL TOOLS #2

    View full-size slide

  85. USEFUL TOOLS #2

    View full-size slide

  86. USEFUL TOOLS #2

    View full-size slide

  87. USEFUL TOOLS #2 (AND #1)

    View full-size slide

  88. USEFUL TOOLS #2 (AND #1)

    View full-size slide

  89. USEFUL TOOLS #2

    View full-size slide

  90. RUNNING YOUR
    OWN OAUTH2
    SERVER

    View full-size slide

  91. USEFUL TOOLS #3

    View full-size slide

  92. USEFUL TOOLS #3

    View full-size slide

  93. RUNNING YOUR OWN OAUTH SERVER

    View full-size slide

  94. RUNNING YOUR OWN OAUTH SERVER
    gB0NV05ehAs8lkQy

    View full-size slide

  95. RUNNING YOUR OWN OAUTH SERVER
    eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE1MDgxNTgxMTIsImlzcyI6Imh0dHBzOi8vdGV
    zdC5tb25rZWhzZXJ2ZXIuY29tL29hdXRoL3Rva2VuIiwic3ViIjoxMDAwLCJleHAiOjE1MDgxNjE3MTIsI
    nNjb3BlIjoicmVhZC1wcml2YXRlIHdyaXRlIiwiYXVkIjoiQkYyMzQ3M0UtQTZBQS00NzdELUFEREVCM
    0E2REMyNEQyOEUifQ.n4b0VpKAgf0BPVPKxjsep9TtqyoexcnygrSekWu2KV4

    View full-size slide

  96. RUNNING YOUR OWN OAUTH SERVER

    View full-size slide

  97. JWTS FOR
    ACCESS TOKENS

    View full-size slide

  98. HEADER
    PAYLOAD
    SIGNATURE
    JWT
    {


    "alg": "HS256",


    "typ": "JWT"


    }
    eyJhbGciOiJIUzI1NiIsInR5cCI6Ikp
    XVCJ9.

    View full-size slide

  99. HEADER
    PAYLOAD
    SIGNATURE
    JWT
    {


    "alg": "HS256",


    "typ": "JWT"


    }
    {


    "iat": 1508158112,


    "iss": "https://test.monkehserver.com/oauth/token",


    "sub": 1000,


    "exp": 1508161712,


    "scope": "read-private write",


    "aud": "BF23473E-A6AA-477D-ADDEB3A6DC24D28E"


    }
    eyJhbGciOiJIUzI1NiIsInR5cCI6Ikp
    XVCJ9.
    eyJhbGciOiJIUzI1NiIsInR5cCI6Ikp
    XVCJ9.eyJpYXQiOjE1MDgxNTgx
    MTIsImlzcyI6Imh0dHBzOi8vdGVz
    dC5tb25rZWhzZXJ2ZXIuY29tL29
    hdXRoL3Rva2VuIiwic3ViIjoxMDA
    wLCJleHAiOjE1MDgxNjE3MTIsIn
    Njb3BlIjoicmVhZC1wcml2YXRlIH
    dyaXRlIiwiYXVkIjoiQkYyMzQ3M0
    UtQTZBQS00NzdELUFEREVCM0E
    2REMyNEQyOEUifQ.

    View full-size slide

  100. HEADER
    PAYLOAD
    SIGNATURE
    JWT
    {


    "alg": "HS256",


    "typ": "JWT"


    }
    {


    "iat": 1508158112,


    "iss": "https://test.monkehserver.com/oauth/token",


    "sub": 1000,


    "exp": 1508161712,


    "scope": "read-private write",


    "aud": "BF23473E-A6AA-477D-ADDEB3A6DC24D28E"


    }
    HMACSHA256(


    base64UrlEncode(header) + "." +


    base64UrlEncode(payload),


    secret


    )
    eyJhbGciOiJIUzI1NiIsInR5cCI6Ikp
    XVCJ9.eyJpYXQiOjE1MDgxNTgx
    MTIsImlzcyI6Imh0dHBzOi8vdGVz
    dC5tb25rZWhzZXJ2ZXIuY29tL29
    hdXRoL3Rva2VuIiwic3ViIjoxMDA
    wLCJleHAiOjE1MDgxNjE3MTIsIn
    Njb3BlIjoicmVhZC1wcml2YXRlIH
    dyaXRlIiwiYXVkIjoiQkYyMzQ3M0
    UtQTZBQS00NzdELUFEREVCM0E
    2REMyNEQyOEUifQ.
    eyJhbGciOiJIUzI1NiIsInR5cCI6Ikp
    XVCJ9.eyJpYXQiOjE1MDgxNTgx
    MTIsImlzcyI6Imh0dHBzOi8vdGVz
    dC5tb25rZWhzZXJ2ZXIuY29tL29
    hdXRoL3Rva2VuIiwic3ViIjoxMDA
    wLCJleHAiOjE1MDgxNjE3MTIsIn
    Njb3BlIjoicmVhZC1wcml2YXRlIH
    dyaXRlIiwiYXVkIjoiQkYyMzQ3M0
    UtQTZBQS00NzdELUFEREVCM0E
    2REMyNEQyOEUifQ.n4b0VpKAgf
    0BPVPKxjsep9TtqyoexcnygrSek
    Wu2KV4

    View full-size slide

  101. RUNNING YOUR OWN OAUTH SERVER (JWT)

    View full-size slide

  102. RUNNING YOUR OWN OAUTH SERVER (JWT)

    View full-size slide

  103. USEFUL TOOLS #4

    View full-size slide

  104. USEFUL TOOLS #4

    View full-size slide

  105. USEFUL TOOLS #4 - JWT.IO

    View full-size slide

  106. OPENID CONNECT

    View full-size slide

  107. OAUTH 2.1
    ➤ PKCE REQUIRED for ALL OAuth clients using authorisation code
    fl
    ow


    ➤ Redirect URI values MUST use exact-string matching


    ➤ Bearer token usage omits the use of bearer tokens in the query string of URIs


    ➤ Refresh Tokens for public clients must either be sender-constrained or one-time use
    (mobile apps and JavaScript apps)

    View full-size slide

  108. BLOG POSTS INCOMING
    monkehworks.com

    View full-size slide

  109. GITHUB
    github.com/coldfumonkeh

    View full-size slide

  110. OAUTH 2 FOR ME AND YOU
    Matt Gi
    ff
    ord - Adobe ColdFusion Summit 2022
    THANK YOU!

    View full-size slide