mirror of
https://github.com/freckle/yesod-auth-oauth2.git
synced 2026-02-19 14:25:47 +01:00
- Update to ghc-8.8 / lts-16.0 - Update to hoauth2 >= 1.11.0 - authGetBS has pre-encoded errors a v1.9 - oauthClientSecret is Maybe at v1.11 - Tweak non-default Resolvers as required
49 lines
1.3 KiB
Haskell
49 lines
1.3 KiB
Haskell
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
module Yesod.Auth.OAuth2.WordPressDotCom
|
|
( oauth2WordPressDotCom
|
|
)
|
|
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 = Just clientSecret
|
|
, oauthOAuthorizeEndpoint =
|
|
"https://public-api.wordpress.com/oauth2/authorize"
|
|
`withQuery` [scopeParam "," ["auth"]]
|
|
, oauthAccessTokenEndpoint =
|
|
"https://public-api.wordpress.com/oauth2/token"
|
|
, oauthCallback = Nothing
|
|
}
|