Skip to content

Commit

Permalink
Upgrade http library to elm-http/2.0.0
Browse files Browse the repository at this point in the history
@github: Fixed #15.
  • Loading branch information
Michael Webb authored and KtorZ committed Jan 7, 2019
1 parent 7f76679 commit d74016e
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 65 deletions.
23 changes: 11 additions & 12 deletions elm.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"type": "package",
"name": "truqu/elm-oauth2",
"version": "4.0.1",
"license": "MIT",
"summary": "OAuth 2.0 client-side utils",
"license": "MIT",
"version": "5.0.0",
"exposed-modules": [
"OAuth",
"OAuth.AuthorizationCode",
Expand All @@ -12,16 +12,15 @@
"OAuth.Password",
"OAuth.Refresh"
],
"elm-version": "0.19.0 <= v < 0.20.0",
"dependencies": {
"elm/core": "1.0.0 <= v < 2.0.0",
"elm/url": "1.0.0 <= v < 2.0.0",
"elm/http": "1.0.0 <= v < 2.0.0",
"elm/json": "1.0.0 <= v < 2.0.0",
"truqu/elm-base64": "2.0.0 <= v < 3.0.0",

"elm/browser": "1.0.1 <= v < 2.0.0",
"elm/core": "1.0.2 <= v < 2.0.0",
"elm/html": "1.0.0 <= v < 2.0.0",
"elm/browser": "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",
"truqu/elm-base64": "2.0.4 <= v < 3.0.0"
},
"test-dependencies": {},
"elm-version": "0.19.0 <= v < 0.20.0"
}
"test-dependencies": {}
}
41 changes: 20 additions & 21 deletions examples/authorization-code/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -55,31 +55,30 @@ type

getUserInfo : OAuthConfiguration -> OAuth.Token -> Cmd Msg
getUserInfo { profileEndpoint, profileDecoder } token =
Http.send GotUserInfo <|
Http.request
{ method = "GET"
, body = Http.emptyBody
, headers = OAuth.useToken token []
, withCredentials = False
, url = Url.toString profileEndpoint
, expect = Http.expectJson profileDecoder
, timeout = Nothing
}
Http.request
{ method = "GET"
, body = Http.emptyBody
, headers = OAuth.useToken token []
, url = Url.toString profileEndpoint
, expect = Http.expectJson GotUserInfo profileDecoder
, timeout = Nothing
, tracker = Nothing
}


getAccessToken : OAuthConfiguration -> Url -> String -> Cmd Msg
getAccessToken ({ clientId, secret, tokenEndpoint } as config) redirectUri code =
Http.send (GotAccessToken config) <|
Http.request <|
OAuth.AuthorizationCode.makeTokenRequest
{ credentials =
{ clientId = clientId
, secret = Just secret
}
, code = code
, url = tokenEndpoint
, redirectUri = redirectUri
Http.request <|
OAuth.AuthorizationCode.makeTokenRequest
{ credentials =
{ clientId = clientId
, secret = Just secret
}
, code = code
, url = tokenEndpoint
, redirectUri = redirectUri
}
(GotAccessToken config)



Expand Down Expand Up @@ -155,7 +154,7 @@ update msg model =

GotAccessToken config res ->
case res of
Err (Http.BadStatus { body }) ->
Err (Http.BadBody body) ->
case Json.decodeString OAuth.AuthorizationCode.defaultAuthenticationErrorDecoder body of
Ok { error, errorDescription } ->
let
Expand Down
19 changes: 9 additions & 10 deletions examples/implicit/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,15 @@ type

getUserInfo : OAuthConfiguration -> OAuth.Token -> Cmd Msg
getUserInfo { profileEndpoint, profileDecoder } token =
Http.send GotUserInfo <|
Http.request
{ method = "GET"
, body = Http.emptyBody
, headers = OAuth.useToken token []
, withCredentials = False
, url = Url.toString profileEndpoint
, expect = Http.expectJson profileDecoder
, timeout = Nothing
}
Http.request
{ method = "GET"
, body = Http.emptyBody
, headers = OAuth.useToken token []
, tracker = Nothing
, url = Url.toString profileEndpoint
, expect = Http.expectJson GotUserInfo profileDecoder
, timeout = Nothing
}



Expand Down
10 changes: 5 additions & 5 deletions src/Internal.elm
Original file line number Diff line number Diff line change
Expand Up @@ -233,15 +233,15 @@ makeAuthUrl responseType { clientId, url, redirectUri, scope, state } =
{ url | query = Just (baseQuery ++ "&" ++ query) }


makeRequest : Url -> List Http.Header -> String -> RequestParts AuthenticationSuccess
makeRequest url headers body =
makeRequest : Url -> List Http.Header -> String -> (Result Http.Error AuthenticationSuccess -> msg) -> RequestParts msg
makeRequest url headers body funcResultToMsg =
{ method = "POST"
, headers = headers
, url = Url.toString url
, body = Http.stringBody "application/x-www-form-urlencoded" body
, expect = Http.expectJson authenticationSuccessDecoder
, expect = Http.expectJson funcResultToMsg authenticationSuccessDecoder
, timeout = Nothing
, withCredentials = False
, tracker = Nothing
}


Expand Down Expand Up @@ -336,7 +336,7 @@ type alias RequestParts a =
, body : Http.Body
, expect : Http.Expect a
, timeout : Maybe Float
, withCredentials : Bool
, tracker : Maybe String
}


Expand Down
10 changes: 5 additions & 5 deletions src/OAuth/AuthorizationCode.elm
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ type alias RequestParts a =
, body : Http.Body
, expect : Http.Expect a
, timeout : Maybe Float
, withCredentials : Bool
, tracker : Maybe String
}


Expand All @@ -360,11 +360,11 @@ type alias Credentials =
{-| Builds a the request components required to get a token from an authorization code
let req : Http.Request AuthenticationSuccess
req = makeTokenRequest authentication |> Http.request
req = makeTokenRequest authentication funcResultToMsg |> Http.request
-}
makeTokenRequest : Authentication -> RequestParts AuthenticationSuccess
makeTokenRequest { credentials, code, url, redirectUri } =
makeTokenRequest : Authentication -> (Result Http.Error AuthenticationSuccess -> msg) -> RequestParts msg
makeTokenRequest { credentials, code, url, redirectUri } funcResultToMsg =
let
body =
[ Builder.string "grant_type" "authorization_code"
Expand All @@ -384,7 +384,7 @@ makeTokenRequest { credentials, code, url, redirectUri } =
Just secret ->
Just { clientId = credentials.clientId, secret = secret }
in
makeRequest url headers body
makeRequest url headers body funcResultToMsg



Expand Down
8 changes: 4 additions & 4 deletions src/OAuth/ClientCredentials.elm
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,11 @@ type alias RequestParts a =
{-| Builds a the request components required to get a token from client credentials
let req : Http.Request TokenResponse
req = makeTokenRequest authentication |> Http.request
req = makeTokenRequest authentication funcResultToMsg |> Http.request
-}
makeTokenRequest : Authentication -> RequestParts AuthenticationSuccess
makeTokenRequest { credentials, scope, url } =
makeTokenRequest : Authentication -> (Result Http.Error AuthenticationSuccess -> msg) -> RequestParts msg
makeTokenRequest { credentials, scope, url } funcResultToMsg =
let
body =
[ Builder.string "grant_type" "client_credentials" ]
Expand All @@ -159,7 +159,7 @@ makeTokenRequest { credentials, scope, url } =
, secret = credentials.secret
}
in
makeRequest url headers body
makeRequest url headers body funcResultToMsg



Expand Down
8 changes: 4 additions & 4 deletions src/OAuth/Password.elm
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,11 @@ type alias RequestParts a =
{-| Builds a the request components required to get a token from the resource owner (user) credentials
let req : Http.Request TokenResponse
req = makeTokenRequest authentication |> Http.request
req = makeTokenRequest authentication funcResultToMsg |> Http.request
-}
makeTokenRequest : Authentication -> RequestParts AuthenticationSuccess
makeTokenRequest { credentials, password, scope, url, username } =
makeTokenRequest : Authentication -> (Result Http.Error AuthenticationSuccess -> msg) -> RequestParts msg
makeTokenRequest { credentials, password, scope, url, username } funcResultToMsg =
let
body =
[ Builder.string "grant_type" "password"
Expand All @@ -161,7 +161,7 @@ makeTokenRequest { credentials, password, scope, url, username } =
headers =
makeHeaders credentials
in
makeRequest url headers body
makeRequest url headers body funcResultToMsg



Expand Down
8 changes: 4 additions & 4 deletions src/OAuth/Refresh.elm
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,11 @@ type alias RequestParts a =
{-| Builds a the request components required to refresh a token
let req : Http.Request TokenResponse
req = makeTokenRequest reqParts |> Http.request
req = makeTokenRequest reqParts funcResultToMsg |> Http.request
-}
makeTokenRequest : Authentication -> RequestParts AuthenticationSuccess
makeTokenRequest { credentials, scope, token, url } =
makeTokenRequest : Authentication -> (Result Http.Error AuthenticationSuccess -> msg) -> RequestParts msg
makeTokenRequest { credentials, scope, token, url } funcResultToMsg =
let
body =
[ Builder.string "grant_type" "refresh_token"
Expand All @@ -152,7 +152,7 @@ makeTokenRequest { credentials, scope, token, url } =
headers =
makeHeaders credentials
in
makeRequest url headers body
makeRequest url headers body funcResultToMsg



Expand Down

0 comments on commit d74016e

Please sign in to comment.