mirror of
https://github.com/freckle/yesod-auth-oauth2.git
synced 2026-01-11 19:58:28 +01:00
Add WordPress.com as an auth provider
Documentation at https://developer.wordpress.com/docs/wpcc/
This commit is contained in:
parent
e483abcbc0
commit
13b84a8724
@ -46,6 +46,7 @@ import Yesod.Auth.OAuth2.Nylas
|
||||
import Yesod.Auth.OAuth2.Salesforce
|
||||
import Yesod.Auth.OAuth2.Slack
|
||||
import Yesod.Auth.OAuth2.Spotify
|
||||
import Yesod.Auth.OAuth2.WordPressDotCom
|
||||
import Yesod.Auth.OAuth2.Upcase
|
||||
|
||||
data App = App
|
||||
@ -145,6 +146,7 @@ mkFoundation = do
|
||||
, loadPlugin oauth2Salesforce "SALES_FORCE"
|
||||
, loadPlugin oauth2Slack "SLACK"
|
||||
, loadPlugin (oauth2Spotify []) "SPOTIFY"
|
||||
, loadPlugin oauth2WordPressDotCom "WORDPRESS_DOT_COM"
|
||||
, loadPlugin oauth2Upcase "UPCASE"
|
||||
]
|
||||
|
||||
|
||||
44
src/Yesod/Auth/OAuth2/WordPressDotCom.hs
Normal file
44
src/Yesod/Auth/OAuth2/WordPressDotCom.hs
Normal file
@ -0,0 +1,44 @@
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Yesod.Auth.OAuth2.WordPressDotCom where
|
||||
|
||||
import qualified Data.Text as T
|
||||
import Yesod.Auth.OAuth2.Prelude
|
||||
|
||||
pluginName :: Text
|
||||
pluginName = "WordPress.com"
|
||||
|
||||
newtype WpUser = WpUser Int
|
||||
|
||||
instance FromJSON WpUser where
|
||||
parseJSON = withObject "WpUser" $ \o -> WpUser
|
||||
<$> o .: "ID"
|
||||
|
||||
oauth2WordPressDotCom
|
||||
:: ( YesodAuth m )
|
||||
=> Text -- client ID
|
||||
-> Text -- client secret
|
||||
-> AuthPlugin m
|
||||
oauth2WordPressDotCom clientId clientSecret =
|
||||
authOAuth2 pluginName oauth2 $ \manager token -> do
|
||||
(WpUser userId, userResponse) <-
|
||||
authGetProfile pluginName manager token
|
||||
"https://public-api.wordpress.com/rest/v1/me/"
|
||||
|
||||
pure Creds
|
||||
{ credsPlugin = pluginName
|
||||
, credsIdent = T.pack $ show userId
|
||||
, credsExtra = setExtra token userResponse
|
||||
}
|
||||
|
||||
where
|
||||
oauth2 = OAuth2
|
||||
{ oauthClientId = clientId
|
||||
, oauthClientSecret = clientSecret
|
||||
, oauthOAuthorizeEndpoint =
|
||||
"https://public-api.wordpress.com/oauth2/authorize"
|
||||
`withQuery` [ scopeParam "," [ "auth" ] ]
|
||||
, oauthAccessTokenEndpoint =
|
||||
"https://public-api.wordpress.com/oauth2/token"
|
||||
, oauthCallback = Nothing
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user