Remove extra fields from Upcase

This commit is contained in:
patrick brisbin 2018-01-27 11:59:04 -05:00
parent 6b3c6af895
commit c586c72df7

View File

@ -5,7 +5,6 @@
-- --
-- * Authenticates against upcase -- * Authenticates against upcase
-- * Uses upcase user id as credentials identifier -- * Uses upcase user id as credentials identifier
-- * Returns first_name, last_name, and email as extras
-- --
module Yesod.Auth.OAuth2.Upcase module Yesod.Auth.OAuth2.Upcase
( oauth2Upcase ( oauth2Upcase
@ -15,45 +14,32 @@ import Yesod.Auth.OAuth2.Prelude
import qualified Data.Text as T import qualified Data.Text as T
data UpcaseUser = UpcaseUser newtype User = User Int
{ upcaseUserId :: Int
, upcaseUserFirstName :: Text
, upcaseUserLastName :: Text
, upcaseUserEmail :: Text
}
instance FromJSON UpcaseUser where instance FromJSON User where
parseJSON = withObject "UpcaseUser" $ \o -> UpcaseUser parseJSON = withObject "User" $ \root -> do
<$> o .: "id" o <- root .: "user"
<*> o .: "first_name" User <$> o .: "id"
<*> o .: "last_name"
<*> o .: "email"
newtype UpcaseResponse = UpcaseResponse UpcaseUser pluginName :: Text
pluginName = "upcase"
instance FromJSON UpcaseResponse where oauth2Upcase :: YesodAuth m => Text -> Text -> AuthPlugin m
parseJSON = withObject "UpcaseResponse" $ \o -> UpcaseResponse oauth2Upcase clientId clientSecret =
<$> o .: "user" authOAuth2 pluginName oauth2 $ \manager token -> do
(User userId, userResponseJSON) <-
authGetProfile pluginName manager token "http://upcase.com/api/v1/me.json"
oauth2Upcase :: YesodAuth m pure Creds
=> Text -- ^ Client ID { credsPlugin = pluginName
-> Text -- ^ Client Secret , credsIdent = T.pack $ show userId
-> AuthPlugin m , credsExtra = setExtra token userResponseJSON
oauth2Upcase clientId clientSecret = authOAuth2 "upcase" }
OAuth2 where
oauth2 = OAuth2
{ oauthClientId = clientId { oauthClientId = clientId
, oauthClientSecret = clientSecret , oauthClientSecret = clientSecret
, oauthOAuthorizeEndpoint = "http://upcase.com/oauth/authorize" , oauthOAuthorizeEndpoint = "http://upcase.com/oauth/authorize"
, oauthAccessTokenEndpoint = "http://upcase.com/oauth/token" , oauthAccessTokenEndpoint = "http://upcase.com/oauth/token"
, oauthCallback = Nothing , oauthCallback = Nothing
} }
$ fromProfileURL "upcase" "http://upcase.com/api/v1/me.json"
$ \user -> Creds
{ credsPlugin = "upcase"
, credsIdent = T.pack $ show $ upcaseUserId user
, credsExtra =
[ ("first_name", upcaseUserFirstName user)
, ("last_name", upcaseUserLastName user)
, ("email", upcaseUserEmail user)
]
}