Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional audience param #4

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ auth0AuthorizeURL
"https://my-app/"
[ "openid", "name", "email" ]
(Just "google-oauth2")
Nothing
```
4 changes: 2 additions & 2 deletions elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "kkpoon/elm-auth0",
"summary": "Auth0 data types and helper functions",
"license": "BSD-3-Clause",
"version": "4.0.0",
"version": "5.0.0",
"exposed-modules": [
"Auth0"
],
Expand All @@ -18,4 +18,4 @@
"rtfeldman/elm-iso8601-date-strings": "1.1.3 <= v < 2.0.0"
},
"test-dependencies": {}
}
}
10 changes: 9 additions & 1 deletion src/Auth0.elm
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ oAuth2IdentityDecoder =
-> String -- redirectURL
-> List String -- scopes
-> Maybe String -- connection
-> Maybe String -- audience
-> String

e.g.
Expand All @@ -178,6 +179,7 @@ e.g.
"https://my-app/"
[ "openid", "name", "email" ]
(Just "google-oauth2")
Nothing

-}
auth0AuthorizeURL :
Expand All @@ -186,13 +188,18 @@ auth0AuthorizeURL :
-> String
-> List String
-> Maybe String
-> Maybe String
-> String
auth0AuthorizeURL auth0Config responseType redirectURL scopes maybeConn =
auth0AuthorizeURL auth0Config responseType redirectURL scopes maybeConn maybeAud =
let
connectionParam =
maybeConn
|> Maybe.map (\c -> "&connection=" ++ c)
|> Maybe.withDefault ""
audParam =
maybeAud
|> Maybe.map (\aud -> "&audience=" ++ aud)
|> Maybe.withDefault ""

scopeParam =
scopes |> String.join " " |> Url.percentEncode
Expand All @@ -202,6 +209,7 @@ auth0AuthorizeURL auth0Config responseType redirectURL scopes maybeConn =
++ ("?response_type=" ++ responseType)
++ ("&client_id=" ++ auth0Config.clientId)
++ connectionParam
++ audParam
++ ("&redirect_uri=" ++ redirectURL)
++ ("&scope=" ++ scopeParam)

Expand Down