Formatting

This commit is contained in:
patrick brisbin 2015-03-24 17:50:24 -04:00
parent bc320b1397
commit 270d1b2eec
No known key found for this signature in database
GPG Key ID: DB04E2CE780A17DE

View File

@ -57,17 +57,17 @@ authOAuth2 name oauth getCreds = AuthPlugin name dispatch login
withCallback csrfToken = do withCallback csrfToken = do
tm <- getRouteToParent tm <- getRouteToParent
render <- lift $ getUrlRender render <- lift getUrlRender
let newEndpoint = oauthOAuthorizeEndpoint oauth <> "&state=" <> encodeUtf8 csrfToken return oauth
return $ oauth { { oauthCallback = Just $ encodeUtf8 $ render $ tm url
oauthCallback = Just $ encodeUtf8 $ render $ tm url, , oauthOAuthorizeEndpoint = oauthOAuthorizeEndpoint oauth
oauthOAuthorizeEndpoint = newEndpoint <> "&state=" <> encodeUtf8 csrfToken
} }
dispatch "GET" ["forward"] = do dispatch "GET" ["forward"] = do
csrfToken <- liftIO $ generateToken csrfToken <- liftIO generateToken
setSession tokenSessionKey csrfToken setSession tokenSessionKey csrfToken
authUrl <- (bsToText . authorizationUrl) <$> withCallback csrfToken authUrl <- bsToText . authorizationUrl <$> withCallback csrfToken
lift $ redirect authUrl lift $ redirect authUrl
dispatch "GET" ["callback"] = do dispatch "GET" ["callback"] = do
@ -90,15 +90,14 @@ authOAuth2 name oauth getCreds = AuthPlugin name dispatch login
dispatch _ _ = notFound dispatch _ _ = notFound
generateToken = (pack . take 30 . randomRs ('a','z')) <$> newStdGen generateToken = pack . take 30 . randomRs ('a', 'z') <$> newStdGen
tokenSessionKey :: Text tokenSessionKey :: Text
tokenSessionKey = "_yesod_oauth2_" <> name tokenSessionKey = "_yesod_oauth2_" <> name
login tm = do login tm = [whamlet|
render <- getUrlRender <a href=@{tm $ oauth2Url name}>Login via #{name}
let oaUrl = render $ tm $ oauth2Url name |]
[whamlet| <a href=#{oaUrl}>Login via #{name} |]
bsToText :: ByteString -> Text bsToText :: ByteString -> Text
bsToText = decodeUtf8With lenientDecode bsToText = decodeUtf8With lenientDecode