mirror of
https://github.com/freckle/yesod-auth-oauth2.git
synced 2026-04-19 17:34:15 +02:00
Add/fix documentation, change argument order
- Document the difference between widget and non-widget functions - Pass the widget as the first argument to take advantage of partial application
This commit is contained in:
parent
023759cebb
commit
a3d8a6cdd5
@ -48,6 +48,10 @@ instance Exception YesodOAuth2Exception
|
|||||||
oauth2Url :: Text -> AuthRoute
|
oauth2Url :: Text -> AuthRoute
|
||||||
oauth2Url name = PluginR name ["forward"]
|
oauth2Url name = PluginR name ["forward"]
|
||||||
|
|
||||||
|
-- | Create an @'AuthPlugin'@ for the given OAuth2 provider
|
||||||
|
--
|
||||||
|
-- Presents a generic @"Login via name"@ link
|
||||||
|
--
|
||||||
authOAuth2 :: YesodAuth m
|
authOAuth2 :: YesodAuth m
|
||||||
=> Text -- ^ Service name
|
=> Text -- ^ Service name
|
||||||
-> OAuth2 -- ^ Service details
|
-> OAuth2 -- ^ Service details
|
||||||
@ -59,21 +63,20 @@ authOAuth2 :: YesodAuth m
|
|||||||
--
|
--
|
||||||
-- See @'fromProfileURL'@ for an example.
|
-- See @'fromProfileURL'@ for an example.
|
||||||
-> AuthPlugin m
|
-> AuthPlugin m
|
||||||
authOAuth2 name oauth getCreds = authOAuth2Widget name oauth getCreds [whamlet|Login via #{name}|]
|
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
|
||||||
|
-- example.
|
||||||
|
--
|
||||||
authOAuth2Widget :: YesodAuth m
|
authOAuth2Widget :: YesodAuth m
|
||||||
=> Text -- ^ Service name
|
=> WidgetT m IO ()
|
||||||
-> OAuth2 -- ^ Service details
|
-> Text
|
||||||
|
-> OAuth2
|
||||||
-> (Manager -> AccessToken -> IO (Creds m))
|
-> (Manager -> AccessToken -> IO (Creds m))
|
||||||
-- ^ This function defines how to take an @'AccessToken'@ and
|
|
||||||
-- retrieve additional information about the user, to be
|
|
||||||
-- set in the session as @'Creds'@. Usually this means a
|
|
||||||
-- second authorized request to @api/me.json@.
|
|
||||||
--
|
|
||||||
-- See @'fromProfileURL'@ for an example.
|
|
||||||
-> WidgetT m IO () -- ^ Widget to be shown instead of "Login with xxx"-Text
|
|
||||||
-> AuthPlugin m
|
-> AuthPlugin m
|
||||||
authOAuth2Widget name oauth getCreds widget = AuthPlugin name dispatch login
|
authOAuth2Widget widget name oauth getCreds = AuthPlugin name dispatch login
|
||||||
|
|
||||||
where
|
where
|
||||||
url = PluginR name ["callback"]
|
url = PluginR name ["callback"]
|
||||||
@ -118,12 +121,9 @@ authOAuth2Widget name oauth getCreds widget = AuthPlugin name dispatch login
|
|||||||
tokenSessionKey :: Text
|
tokenSessionKey :: Text
|
||||||
tokenSessionKey = "_yesod_oauth2_" <> name
|
tokenSessionKey = "_yesod_oauth2_" <> name
|
||||||
|
|
||||||
login tm = [whamlet|
|
login tm = [whamlet|<a href=@{tm $ oauth2Url name}>^{widget}|]
|
||||||
<a href=@{tm $ oauth2Url name}>
|
|
||||||
^{widget}
|
|
||||||
|]
|
|
||||||
|
|
||||||
-- | Handle the common case of fetching Profile information a JSON endpoint
|
-- | Handle the common case of fetching Profile information from a JSON endpoint
|
||||||
--
|
--
|
||||||
-- Throws @'InvalidProfileResponse'@ if JSON parsing fails
|
-- Throws @'InvalidProfileResponse'@ if JSON parsing fails
|
||||||
--
|
--
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user