-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
87a0231
commit 553e048
Showing
3 changed files
with
54 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters