Skip to content

Commit

Permalink
add support for RFC7636 - Proof Key for Code Exchange
Browse files Browse the repository at this point in the history
Auth 2.0 public clients utilizing the Authorization Code Grant are
susceptible to the authorization code interception attack.  This
specification describes the attack as well as a technique to mitigate
against the threat through the use of Proof Key for Code Exchange
(PKCE, pronounced "pixy").
  • Loading branch information
KtorZ committed Feb 17, 2020
1 parent a1379c7 commit f1f648a
Show file tree
Hide file tree
Showing 5 changed files with 627 additions and 5 deletions.
4 changes: 4 additions & 0 deletions elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"exposed-modules": [
"OAuth",
"OAuth.AuthorizationCode",
"OAuth.AuthorizationCode.PKCE",
"OAuth.Implicit",
"OAuth.ClientCredentials",
"OAuth.Password",
Expand All @@ -15,11 +16,14 @@
"elm-version": "0.19.0 <= v < 0.20.0",
"dependencies": {
"elm/browser": "1.0.1 <= v < 2.0.0",
"elm/bytes": "1.0.8 <= v < 2.0.0",
"elm/core": "1.0.2 <= v < 2.0.0",
"elm/html": "1.0.0 <= v < 2.0.0",
"elm/http": "2.0.0 <= v < 3.0.0",
"elm/json": "1.1.2 <= v < 2.0.0",
"elm/url": "1.0.0 <= v < 2.0.0",
"folkertdev/elm-sha2": "1.0.0 <= v < 2.0.0",
"ivadzy/bbase64": "1.1.1 <= v < 2.0.0",
"truqu/elm-base64": "2.0.4 <= v < 3.0.0"
},
"test-dependencies": {}
Expand Down
6 changes: 5 additions & 1 deletion src/Internal.elm
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ urlAddMaybe param ms qs =


makeAuthorizationUrl : ResponseType -> Authorization -> Url
makeAuthorizationUrl responseType { clientId, url, redirectUri, scope, state } =
makeAuthorizationUrl responseType { clientId, url, redirectUri, scope, state, codeChallenge } =
let
query =
[ Builder.string "client_id" clientId
Expand All @@ -222,6 +222,9 @@ makeAuthorizationUrl responseType { clientId, url, redirectUri, scope, state } =
]
|> urlAddList "scope" scope
|> urlAddMaybe "state" state
|> urlAddMaybe "code_challenge" codeChallenge
|> urlAddMaybe "code_challenge_method"
(Maybe.map (always "S256") codeChallenge)
|> Builder.toQuery
|> String.dropLeft 1
in
Expand Down Expand Up @@ -346,6 +349,7 @@ type alias Authorization =
, redirectUri : Url
, scope : List String
, state : Maybe String
, codeChallenge : Maybe String
}


Expand Down
12 changes: 10 additions & 2 deletions src/OAuth/AuthorizationCode.elm
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,16 @@ type AuthorizationResult
authorization flow.
-}
makeAuthorizationUrl : Authorization -> Url
makeAuthorizationUrl =
Internal.makeAuthorizationUrl Internal.Code
makeAuthorizationUrl { clientId, url, redirectUri, scope, state } =
Internal.makeAuthorizationUrl
Internal.Code
{ clientId = clientId
, url = url
, redirectUri = redirectUri
, scope = scope
, state = state
, codeChallenge = Nothing
}


{-| Parse the location looking for a parameters set by the resource provider server after
Expand Down
Loading

0 comments on commit f1f648a

Please sign in to comment.