mirror of
https://github.com/freckle/yesod-auth-oauth2.git
synced 2026-09-10 19:34:56 +02:00
Experimental extra credentials fix. Also adds .:? combinator in Spotify.hs
This commit is contained in:
parent
8241ef5e97
commit
d2bf3f90a6
@ -15,6 +15,7 @@ module Yesod.Auth.OAuth2
|
|||||||
, oauth2Url
|
, oauth2Url
|
||||||
, fromProfileURL
|
, fromProfileURL
|
||||||
, YesodOAuth2Exception(..)
|
, YesodOAuth2Exception(..)
|
||||||
|
, maybeExtra
|
||||||
, module Network.OAuth.OAuth2
|
, module Network.OAuth.OAuth2
|
||||||
) where
|
) where
|
||||||
|
|
||||||
@ -149,3 +150,9 @@ appendQuery url query =
|
|||||||
if '?' `C8.elem` url
|
if '?' `C8.elem` url
|
||||||
then url <> "&" <> query
|
then url <> "&" <> query
|
||||||
else url <> "?" <> query
|
else url <> "?" <> query
|
||||||
|
|
||||||
|
-- | A helper for providing an optional value to credsExtra
|
||||||
|
--
|
||||||
|
maybeExtra :: Text -> Maybe Text -> [(Text, Text)]
|
||||||
|
maybeExtra k (Just v) = [(k, v)]
|
||||||
|
maybeExtra _ Nothing = []
|
||||||
|
|||||||
@ -106,19 +106,10 @@ toCreds user userMails token = Creds
|
|||||||
, ("avatar_url", githubUserAvatarUrl user)
|
, ("avatar_url", githubUserAvatarUrl user)
|
||||||
, ("access_token", decodeUtf8 $ accessToken token)
|
, ("access_token", decodeUtf8 $ accessToken token)
|
||||||
]
|
]
|
||||||
++ maybeName (githubUserName user)
|
++ maybeExtra "name" (githubUserName user)
|
||||||
++ maybePublicEmail (githubUserPublicEmail user)
|
++ maybeExtra "email" (githubUserPublicEmail user)
|
||||||
++ maybeLocation (githubUserLocation user)
|
++ maybeExtra "location" (githubUserLocation user)
|
||||||
}
|
}
|
||||||
|
|
||||||
where
|
where
|
||||||
email = fromMaybe (head userMails) $ find githubUserEmailPrimary userMails
|
email = fromMaybe (head userMails) $ find githubUserEmailPrimary userMails
|
||||||
|
|
||||||
maybeName Nothing = []
|
|
||||||
maybeName (Just name) = [("name", name)]
|
|
||||||
|
|
||||||
maybePublicEmail Nothing = []
|
|
||||||
maybePublicEmail (Just e) = [("public_email", e)]
|
|
||||||
|
|
||||||
maybeLocation Nothing = []
|
|
||||||
maybeLocation (Just location) = [("location", location)]
|
|
||||||
|
|||||||
@ -29,7 +29,6 @@ import Control.Exception.Lifted
|
|||||||
import Control.Monad (mzero)
|
import Control.Monad (mzero)
|
||||||
import Data.Aeson
|
import Data.Aeson
|
||||||
import Data.Monoid ((<>))
|
import Data.Monoid ((<>))
|
||||||
import Data.Maybe (maybeToList)
|
|
||||||
import Data.Text (Text)
|
import Data.Text (Text)
|
||||||
import Data.Text.Encoding (encodeUtf8, decodeUtf8)
|
import Data.Text.Encoding (encodeUtf8, decodeUtf8)
|
||||||
import Network.HTTP.Conduit (Manager)
|
import Network.HTTP.Conduit (Manager)
|
||||||
@ -135,8 +134,6 @@ uidBuilder f user token = Creds
|
|||||||
, ("family_name", googleUserFamilyName user)
|
, ("family_name", googleUserFamilyName user)
|
||||||
, ("avatar_url", googleUserPicture user)
|
, ("avatar_url", googleUserPicture user)
|
||||||
, ("access_token", decodeUtf8 $ accessToken token)
|
, ("access_token", decodeUtf8 $ accessToken token)
|
||||||
] ++ maybeHostedDomain
|
]
|
||||||
|
++ maybeExtra "hosted_domain" (googleUserHostedDomain user)
|
||||||
}
|
}
|
||||||
|
|
||||||
where
|
|
||||||
maybeHostedDomain = maybeToList $ (,) "hosted_domain" <$> googleUserHostedDomain user
|
|
||||||
|
|||||||
@ -33,8 +33,8 @@ data SpotifyUserImage = SpotifyUserImage
|
|||||||
|
|
||||||
instance FromJSON SpotifyUserImage where
|
instance FromJSON SpotifyUserImage where
|
||||||
parseJSON (Object v) = SpotifyUserImage
|
parseJSON (Object v) = SpotifyUserImage
|
||||||
<$> v .: "height"
|
<$> v .:? "height"
|
||||||
<*> v .: "width"
|
<*> v .:? "width"
|
||||||
<*> v .: "url"
|
<*> v .: "url"
|
||||||
|
|
||||||
parseJSON _ = mzero
|
parseJSON _ = mzero
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user