Cleanup WordPress plugin

- Explicit exports
- Fixup Haddock formatting
- Brittany & Stylish
- CHANGELOG attribution
This commit is contained in:
patrick brisbin 2020-08-19 11:15:53 -04:00
parent 40119bd1f3
commit 60c0f68d5a
No known key found for this signature in database
GPG Key ID: 20299C6982D938FB
2 changed files with 15 additions and 10 deletions

View File

@ -1,6 +1,7 @@
## [*Unreleased*](https://github.com/thoughtbot/yesod-auth-oauth2/compare/v0.6.1.2...master)
- Add WordPress.com provider
[@nbloomf](https://github.com/thoughtbot/yesod-auth-oauth2/pull/130)
## [v0.6.1.2](https://github.com/thoughtbot/yesod-auth-oauth2/compare/v0.6.1.1...v0.6.1.2)

View File

@ -1,6 +1,9 @@
{-# LANGUAGE OverloadedStrings #-}
module Yesod.Auth.OAuth2.WordPressDotCom where
module Yesod.Auth.OAuth2.WordPressDotCom
( oauth2WordPressDotCom
)
where
import qualified Data.Text as T
import Yesod.Auth.OAuth2.Prelude
@ -11,19 +14,20 @@ pluginName = "WordPress.com"
newtype WpUser = WpUser Int
instance FromJSON WpUser where
parseJSON = withObject "WpUser" $ \o -> WpUser
<$> o .: "ID"
parseJSON = withObject "WpUser" $ \o -> WpUser <$> o .: "ID"
oauth2WordPressDotCom
:: ( YesodAuth m )
=> Text -- client ID
-> Text -- client secret
:: (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/"
(WpUser userId, userResponse) <- authGetProfile
pluginName
manager
token
"https://public-api.wordpress.com/rest/v1/me/"
pure Creds
{ credsPlugin = pluginName
@ -37,7 +41,7 @@ oauth2WordPressDotCom clientId clientSecret =
, oauthClientSecret = clientSecret
, oauthOAuthorizeEndpoint =
"https://public-api.wordpress.com/oauth2/authorize"
`withQuery` [ scopeParam "," [ "auth" ] ]
`withQuery` [scopeParam "," ["auth"]]
, oauthAccessTokenEndpoint =
"https://public-api.wordpress.com/oauth2/token"
, oauthCallback = Nothing