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