Fixes #42; slightly nicer error message when no 'code' field.

This commit is contained in:
silky 2015-10-13 15:22:57 +11:00
parent 4afaba6645
commit 348ffd9a01
2 changed files with 14 additions and 11 deletions

View File

@ -102,15 +102,18 @@ authOAuth2Widget widget name oauth getCreds = AuthPlugin name dispatch login
deleteSession tokenSessionKey
case newToken of
Just csrfToken | newToken == oldToken -> do
code <- lift $ runInputGet $ ireq textField "code"
oauth' <- withCallback csrfToken
master <- lift getYesod
result <- liftIO $ fetchAccessToken (authHttpManager master) oauth' (encodeUtf8 code)
case result of
Left _ -> permissionDenied "Unable to retreive OAuth2 token"
Right token -> do
creds <- liftIO $ getCreds (authHttpManager master) token
lift $ setCredsRedirect creds
mcode <- lift $ runInputGet $ iopt textField "code"
case mcode of
Nothing -> permissionDenied "`Code` field not provided."
Just code -> do
oauth' <- withCallback csrfToken
master <- lift getYesod
result <- liftIO $ fetchAccessToken (authHttpManager master) oauth' (encodeUtf8 code)
case result of
Left _ -> permissionDenied "Unable to retreive OAuth2 token"
Right token -> do
creds <- liftIO $ getCreds (authHttpManager master) token
lift $ setCredsRedirect creds
_ ->
permissionDenied "Invalid OAuth2 state token"

View File

@ -1,5 +1,5 @@
name: yesod-auth-oauth2
version: 0.1.4
version: 0.1.5
license: BSD3
license-file: LICENSE
author: Tom Streller
@ -52,4 +52,4 @@ library
source-repository head
type: git
location: https://github.com/thoughtbot/authenticate-oauth2.git
location: https://github.com/thoughtbot/yesod-auth-oauth2.git