Skip to content

Commit

Permalink
remove 'authorization_code' example
Browse files Browse the repository at this point in the history
In the end, there's not much reason why this example should exist.  The
code is there for completeness but obviously, it is wrong to use the
library as is in a public setup. When dealing with client applications,
the 'implicit' flow ought to be the way to go and therefore, it's better
to advertise this only.
  • Loading branch information
KtorZ committed Sep 3, 2018
1 parent ef85924 commit 88f27a7
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 491 deletions.
98 changes: 0 additions & 98 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,104 +122,6 @@ getUserProfile endpoint token =
```


### Usage (Authorization Code Flow)

A complete example is available
[here](https://truqu.github.io/elm-oauth2/examples/authorization_code)
(with the corresponding sources [here](https://github.com/truqu/elm-oauth2/tree/master/examples/authorization_code))


##### Imports
```elm
import OAuth
import OAuth.AuthorizationCode
```

##### Authorizing & Authenticating

```elm
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
NoOp ->
model ! []

Authorize ->
model
! [ OAuth.AuthorizationCode.authorize
{ clientId = "clientId"
, redirectUri = "redirectUri"
, responseType = OAuth.Code -- Use the OAuth.Code response type
, scope = [ "whatever" ]
, state = Nothing
, url = "authorizationEndpoint"
}
]

Authenticate res ->
case res of
-- Http request didn't go through
Err err ->
model ! []

-- Token received from the server
Ok { token } ->

```

##### Parsing the token

```elm
init : Navigation.Location -> ( Model, Cmd Msg )
init location =
let
model = {}
in
case OAuth.AuthorizationCode.parse location of
-- A token has been parsed
Ok { code } ->
let
req =
OAuth.AuthorizationCode.authenticate <|
OAuth.AuthorizationCode
{ credentials = { clientId = "clientId", secret = "secret" }
, code = code
, redirectUri = "redirectUri"
, scope = [ "whatever" ]
, state = Nothing
, url = "tokenEndpoint"
}
in
model [ Http.send Authenticate req ]

-- Nothing to parse, unauthenticated
Err OAuth.Empty ->
model ! []

-- An other type of error (invalid parsing or an actual OAuth error)
Err _ ->
model ! []
```


##### Using the token

```elm
let
req =
Http.request
{ method = "GET"
, body = Http.emptyBody
, headers = OAuth.use token [] -- Add the token to the http headers
, withCredentials = False
, url = "whatever"
, expect = Http.expectJson decoder
, timeout = Nothing
}
in
{ model | token = Just token } ! [ Http.send handleResponse req ]
```

### TroubleShooting

##### Interacting with GitHub
Expand Down
Loading

0 comments on commit 88f27a7

Please sign in to comment.