mirror of
https://github.com/freckle/yesod-auth-oauth2.git
synced 2026-04-29 06:04:51 +02:00
orcid auth plugin
This commit is contained in:
parent
acb69f8da4
commit
a0a996aed2
@ -40,6 +40,7 @@ import Yesod.Auth.OAuth2.Spotify
|
|||||||
import Yesod.Auth.OAuth2.Twitch
|
import Yesod.Auth.OAuth2.Twitch
|
||||||
import Yesod.Auth.OAuth2.Upcase
|
import Yesod.Auth.OAuth2.Upcase
|
||||||
import Yesod.Auth.OAuth2.WordPressDotCom
|
import Yesod.Auth.OAuth2.WordPressDotCom
|
||||||
|
import Yesod.Auth.OAuth2.ORCID
|
||||||
|
|
||||||
data App = App
|
data App = App
|
||||||
{ appHttpManager :: Manager
|
{ appHttpManager :: Manager
|
||||||
@ -149,6 +150,7 @@ mkFoundation = do
|
|||||||
, loadPlugin (oauth2Spotify []) "SPOTIFY"
|
, loadPlugin (oauth2Spotify []) "SPOTIFY"
|
||||||
, loadPlugin oauth2Twitch "TWITCH"
|
, loadPlugin oauth2Twitch "TWITCH"
|
||||||
, loadPlugin oauth2WordPressDotCom "WORDPRESS_DOT_COM"
|
, loadPlugin oauth2WordPressDotCom "WORDPRESS_DOT_COM"
|
||||||
|
, loadPlugin oauth2Orcid "ORCID"
|
||||||
, loadPlugin oauth2Upcase "UPCASE"
|
, loadPlugin oauth2Upcase "UPCASE"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
50
src/Yesod/Auth/OAuth2/ORCID.hs
Normal file
50
src/Yesod/Auth/OAuth2/ORCID.hs
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
|
|
||||||
|
module Yesod.Auth.OAuth2.Orcid
|
||||||
|
( oauth2Orcid
|
||||||
|
) where
|
||||||
|
|
||||||
|
import qualified Data.Text as T
|
||||||
|
import Yesod.Auth.OAuth2.Prelude
|
||||||
|
|
||||||
|
pluginName :: Text
|
||||||
|
pluginName = "orcid"
|
||||||
|
|
||||||
|
newtype User = User Text
|
||||||
|
|
||||||
|
instance FromJSON User where
|
||||||
|
parseJSON = withObject "User" $ \o -> User <$> o .: "sub"
|
||||||
|
|
||||||
|
oauth2Orcid
|
||||||
|
:: YesodAuth m
|
||||||
|
=> Text
|
||||||
|
-- ^ Client Id
|
||||||
|
-> Text
|
||||||
|
-- ^ Client Secret
|
||||||
|
-> AuthPlugin m
|
||||||
|
oauth2Orcid clientId clientSecret =
|
||||||
|
authOAuth2 pluginName oauth2 $ \manager token -> do
|
||||||
|
(User userId, userResponse) <-
|
||||||
|
authGetProfile
|
||||||
|
pluginName
|
||||||
|
manager
|
||||||
|
token
|
||||||
|
"https://orcid.org/oauth/userinfo"
|
||||||
|
|
||||||
|
pure
|
||||||
|
Creds
|
||||||
|
{ credsPlugin = pluginName
|
||||||
|
, credsIdent = T.pack $ show userId
|
||||||
|
, credsExtra = setExtra token userResponse
|
||||||
|
}
|
||||||
|
where
|
||||||
|
oauth2 =
|
||||||
|
OAuth2
|
||||||
|
{ oauth2ClientId = clientId
|
||||||
|
, oauth2ClientSecret = Just clientSecret
|
||||||
|
, oauth2AuthorizeEndpoint =
|
||||||
|
"https://orcid.org/oauth/authorize"
|
||||||
|
`withQuery` [scopeParam " " ["openid"]]
|
||||||
|
, oauth2TokenEndpoint = "https://orcid.org/oauth/token"
|
||||||
|
, oauth2RedirectUri = Nothing
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user