yesod-auth-oauth2 0.6.1.5 → 0.6.1.6
raw patch · 4 files changed
+76/−20 lines, 4 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
+ Yesod.Auth.OAuth2: authOAuth2' :: YesodAuth m => Text -> OAuth2 -> FetchCreds m -> AuthPlugin m
+ Yesod.Auth.OAuth2: authOAuth2Widget' :: YesodAuth m => WidgetFor m () -> Text -> OAuth2 -> FetchCreds m -> AuthPlugin m
+ Yesod.Auth.OAuth2.Dispatch: fetchAccessToken :: Manager -> OAuth2 -> ExchangeToken -> IO (OAuth2Result Errors OAuth2Token)
+ Yesod.Auth.OAuth2.Dispatch: fetchAccessToken2 :: Manager -> OAuth2 -> ExchangeToken -> IO (OAuth2Result Errors OAuth2Token)
+ Yesod.Auth.OAuth2.Dispatch: type FetchToken = Manager -> OAuth2 -> ExchangeToken -> IO (OAuth2Result Errors OAuth2Token)
- Yesod.Auth.OAuth2.Dispatch: dispatchAuthRequest :: Text -> OAuth2 -> FetchCreds m -> Text -> [Text] -> AuthHandler m TypedContent
+ Yesod.Auth.OAuth2.Dispatch: dispatchAuthRequest :: Text -> OAuth2 -> FetchToken -> FetchCreds m -> Text -> [Text] -> AuthHandler m TypedContent
- Yesod.Auth.OAuth2.Prelude: type family AuthId master :: Type;
+ Yesod.Auth.OAuth2.Prelude: type family AuthId master;
- Yesod.Auth.OAuth2.Prelude: withObject :: () => String -> (Object -> Parser a) -> Value -> Parser a
+ Yesod.Auth.OAuth2.Prelude: withObject :: String -> (Object -> Parser a) -> Value -> Parser a
Files
- CHANGELOG.md +6/−1
- src/Yesod/Auth/OAuth2.hs +43/−9
- src/Yesod/Auth/OAuth2/Dispatch.hs +25/−8
- yesod-auth-oauth2.cabal +2/−2
CHANGELOG.md view
@@ -1,6 +1,11 @@-## [*Unreleased*](https://github.com/thoughtbot/yesod-auth-oauth2/compare/v0.6.1.5...master)+## [*Unreleased*](https://github.com/thoughtbot/yesod-auth-oauth2/compare/v0.6.1.6...master) None++## [v0.6.1.6](https://github.com/thoughtbot/yesod-auth-oauth2/compare/v0.6.1.5...v0.6.1.6)++- Revert back to Authorization-header-only `fetchAccessToken` function+- Add `authOAuth2'` and `authOAuth2Widget'`, which use `fetchAccessToken2` ## [v0.6.1.5](https://github.com/thoughtbot/yesod-auth-oauth2/compare/v0.6.1.4...v0.6.1.5)
src/Yesod/Auth/OAuth2.hs view
@@ -17,12 +17,17 @@ , authOAuth2 , authOAuth2Widget + -- * Alternatives that use 'fetchAccessToken2'+ , authOAuth2'+ , authOAuth2Widget'+ -- * Reading our @'credsExtra'@ keys , getAccessToken , getRefreshToken , getUserResponse , getUserResponseJSON- ) where+ )+where import Control.Error.Util (note) import Control.Monad ((<=<))@@ -46,6 +51,13 @@ authOAuth2 :: YesodAuth m => Text -> OAuth2 -> FetchCreds m -> AuthPlugin m authOAuth2 name = authOAuth2Widget [whamlet|Login via #{name}|] name +-- | A version of 'authOAuth2' that uses 'fetchAccessToken2'+--+-- See <https://github.com/thoughtbot/yesod-auth-oauth2/pull/129>+--+authOAuth2' :: YesodAuth m => Text -> OAuth2 -> FetchCreds m -> AuthPlugin m+authOAuth2' name = authOAuth2Widget' [whamlet|Login via #{name}|] name+ -- | Create an @'AuthPlugin'@ for the given OAuth2 provider -- -- Allows passing a custom widget for the login link. See @'oauth2Eve'@ for an@@ -58,23 +70,45 @@ -> OAuth2 -> FetchCreds m -> AuthPlugin m-authOAuth2Widget widget name oauth getCreds =- AuthPlugin name (dispatchAuthRequest name oauth getCreds) login- where- login tm = [whamlet|<a href=@{tm $ oauth2Url name}>^{widget}|]+authOAuth2Widget = buildPlugin fetchAccessToken +-- | A version of 'authOAuth2Widget' that uses 'fetchAccessToken2'+--+-- See <https://github.com/thoughtbot/yesod-auth-oauth2/pull/129>+--+authOAuth2Widget'+ :: YesodAuth m+ => WidgetFor m ()+ -> Text+ -> OAuth2+ -> FetchCreds m+ -> AuthPlugin m+authOAuth2Widget' = buildPlugin fetchAccessToken2++buildPlugin+ :: YesodAuth m+ => FetchToken+ -> WidgetFor m ()+ -> Text+ -> OAuth2+ -> FetchCreds m+ -> AuthPlugin m+buildPlugin getToken widget name oauth getCreds = AuthPlugin+ name+ (dispatchAuthRequest name oauth getToken getCreds)+ login+ where login tm = [whamlet|<a href=@{tm $ oauth2Url name}>^{widget}|]+ -- | Read the @'AccessToken'@ from the values set via @'setExtra'@ getAccessToken :: Creds m -> Maybe AccessToken-getAccessToken =- (AccessToken <$>) . lookup "accessToken" . credsExtra+getAccessToken = (AccessToken <$>) . lookup "accessToken" . credsExtra -- | Read the @'RefreshToken'@ from the values set via @'setExtra'@ -- -- N.B. not all providers supply this value. -- getRefreshToken :: Creds m -> Maybe RefreshToken-getRefreshToken =- (RefreshToken <$>) . lookup "refreshToken" . credsExtra+getRefreshToken = (RefreshToken <$>) . lookup "refreshToken" . credsExtra -- | Read the original profile response from the values set via @'setExtra'@ getUserResponse :: Creds m -> Maybe ByteString
src/Yesod/Auth/OAuth2/Dispatch.hs view
@@ -8,7 +8,10 @@ {-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeFamilies #-} module Yesod.Auth.OAuth2.Dispatch- ( FetchCreds+ ( FetchToken+ , fetchAccessToken+ , fetchAccessToken2+ , FetchCreds , dispatchAuthRequest ) where@@ -23,12 +26,20 @@ import Data.Text.Encoding (decodeUtf8, encodeUtf8) import Network.HTTP.Conduit (Manager) import Network.OAuth.OAuth2+import Network.OAuth.OAuth2.TokenRequest (Errors) import URI.ByteString.Extension import Yesod.Auth hiding (ServerError) import Yesod.Auth.OAuth2.ErrorResponse import Yesod.Auth.OAuth2.Exception import Yesod.Core hiding (ErrorResponse) +-- | How to fetch an @'OAuth2Token'@+--+-- This will be 'fetchAccessToken' or 'fetchAccessToken2'+--+type FetchToken+ = Manager -> OAuth2 -> ExchangeToken -> IO (OAuth2Result Errors OAuth2Token)+ -- | How to take an @'OAuth2Token'@ and retrieve user credentials type FetchCreds m = Manager -> OAuth2Token -> IO (Creds m) @@ -36,15 +47,16 @@ dispatchAuthRequest :: Text -- ^ Name -> OAuth2 -- ^ Service details+ -> FetchToken -- ^ How to get a token -> FetchCreds m -- ^ How to get credentials -> Text -- ^ Method -> [Text] -- ^ Path pieces -> AuthHandler m TypedContent-dispatchAuthRequest name oauth2 _ "GET" ["forward"] =+dispatchAuthRequest name oauth2 _ _ "GET" ["forward"] = dispatchForward name oauth2-dispatchAuthRequest name oauth2 getCreds "GET" ["callback"] =- dispatchCallback name oauth2 getCreds-dispatchAuthRequest _ _ _ _ _ = notFound+dispatchAuthRequest name oauth2 getToken getCreds "GET" ["callback"] =+ dispatchCallback name oauth2 getToken getCreds+dispatchAuthRequest _ _ _ _ _ _ = notFound -- | Handle @GET \/forward@ --@@ -63,14 +75,19 @@ -- 2. Use the code parameter to fetch an AccessToken for the Provider -- 3. Use the AccessToken to construct a @'Creds'@ value for the Provider ---dispatchCallback :: Text -> OAuth2 -> FetchCreds m -> AuthHandler m TypedContent-dispatchCallback name oauth2 getCreds = do+dispatchCallback+ :: Text+ -> OAuth2+ -> FetchToken+ -> FetchCreds m+ -> AuthHandler m TypedContent+dispatchCallback name oauth2 getToken getCreds = do csrf <- verifySessionCSRF $ tokenSessionKey name onErrorResponse $ oauth2HandshakeError name code <- requireGetParam "code" manager <- authHttpManager oauth2' <- withCallbackAndState name oauth2 csrf- token <- errLeft $ fetchAccessToken2 manager oauth2' $ ExchangeToken code+ token <- errLeft $ getToken manager oauth2' $ ExchangeToken code creds <- errLeft $ tryFetchCreds $ getCreds manager token setCredsRedirect creds where
yesod-auth-oauth2.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: 3e66a5211c9fd4ac4c5addba52631217bcef9d304e428821d6f77d7e10dc648e+-- hash: 6a7af938916ceb13a17b17597d66da9212c38008e00c2ff2c2ea546ff6d96d0d name: yesod-auth-oauth2-version: 0.6.1.5+version: 0.6.1.6 synopsis: OAuth 2.0 authentication plugins description: Library to authenticate with OAuth 2.0 for Yesod web applications. category: Web