mirror of
https://github.com/freckle/yesod-auth-oauth2.git
synced 2026-09-09 03:13:49 +02:00
Fixes to EveOnline plugin
- Fix invalid data declaration - Fix -Wall compilation warnings - Unused imports - Unused functions - Unused arguments - Shadowed function name - Incorporate plain link into WidgetType, remove Maybe - Use only one function, always accept WidgetType
This commit is contained in:
parent
a3d8a6cdd5
commit
a8396dddf0
@ -11,7 +11,6 @@
|
|||||||
--
|
--
|
||||||
module Yesod.Auth.OAuth2.EveOnline
|
module Yesod.Auth.OAuth2.EveOnline
|
||||||
( oauth2Eve
|
( oauth2Eve
|
||||||
, oauth2EveWidget
|
|
||||||
, oauth2EveScoped
|
, oauth2EveScoped
|
||||||
, WidgetType(..)
|
, WidgetType(..)
|
||||||
, module Yesod.Auth.OAuth2
|
, module Yesod.Auth.OAuth2
|
||||||
@ -25,9 +24,8 @@ import Control.Exception.Lifted
|
|||||||
import Control.Monad (mzero)
|
import Control.Monad (mzero)
|
||||||
import Data.Aeson
|
import Data.Aeson
|
||||||
import Data.Monoid ((<>))
|
import Data.Monoid ((<>))
|
||||||
import Data.Text as T (Text,unwords)
|
import Data.Text (Text)
|
||||||
import Data.ByteString as B (ByteString)
|
import Data.Text.Encoding (encodeUtf8)
|
||||||
import Data.Text.Encoding (encodeUtf8, decodeUtf8)
|
|
||||||
import Network.HTTP.Conduit (Manager)
|
import Network.HTTP.Conduit (Manager)
|
||||||
import Yesod.Auth
|
import Yesod.Auth
|
||||||
import Yesod.Auth.OAuth2
|
import Yesod.Auth.OAuth2
|
||||||
@ -35,18 +33,19 @@ import Yesod.Core.Widget
|
|||||||
|
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
|
|
||||||
data YesodAuth m => WidgetType m
|
data WidgetType m
|
||||||
= BigWhite
|
= Plain -- ^ Simple "Login via eveonline" text
|
||||||
|
| BigWhite
|
||||||
| SmallWhite
|
| SmallWhite
|
||||||
| BigBlack
|
| BigBlack
|
||||||
| SmallBlack
|
| SmallBlack
|
||||||
| Custom (WidgetT m IO ())
|
| Custom (WidgetT m IO ())
|
||||||
|
|
||||||
data EveUser = EveUser
|
data EveUser = EveUser
|
||||||
{ eveUserId :: Int
|
{ _eveUserId :: Int
|
||||||
, eveUserName :: Text
|
, eveUserName :: Text
|
||||||
, eveUserExpire :: Text
|
, eveUserExpire :: Text
|
||||||
, eveScopes :: [Text]
|
, _eveScopes :: [Text]
|
||||||
, eveTokenType :: Text
|
, eveTokenType :: Text
|
||||||
, eveCharOwnerHash :: Text
|
, eveCharOwnerHash :: Text
|
||||||
}
|
}
|
||||||
@ -65,33 +64,28 @@ instance FromJSON EveUser where
|
|||||||
oauth2Eve :: YesodAuth m
|
oauth2Eve :: YesodAuth m
|
||||||
=> Text -- ^ Client ID
|
=> Text -- ^ Client ID
|
||||||
-> Text -- ^ Client Secret
|
-> Text -- ^ Client Secret
|
||||||
|
-> WidgetType m
|
||||||
-> AuthPlugin m
|
-> AuthPlugin m
|
||||||
oauth2Eve clientId clientSecret = oauth2EveScoped clientId clientSecret ["publicData"] Nothing
|
oauth2Eve clientId clientSecret = oauth2EveScoped clientId clientSecret ["publicData"] . asWidget
|
||||||
|
|
||||||
oauth2EveWidget :: YesodAuth m
|
|
||||||
=> Text -- ^ Client ID
|
|
||||||
-> Text -- ^ Client Secret
|
|
||||||
-> WidgetType m
|
|
||||||
-> AuthPlugin m
|
|
||||||
oauth2EveWidget clientId clientSecret w = oauth2EveScoped clientId clientSecret ["publicData"] (Just . toWidget $ w)
|
|
||||||
where
|
where
|
||||||
toWidget :: YesodAuth m => WidgetType m -> WidgetT m IO ()
|
asWidget :: YesodAuth m => WidgetType m -> WidgetT m IO ()
|
||||||
toWidget BigWhite = [whamlet|<img src="https://images.contentful.com/idjq7aai9ylm/4PTzeiAshqiM8osU2giO0Y/5cc4cb60bac52422da2e45db87b6819c/EVE_SSO_Login_Buttons_Large_White.png?w=270&h=45">|]
|
asWidget Plain = [whamlet|Login via eveonline|]
|
||||||
toWidget BigBlack = [whamlet|<img src="https://images.contentful.com/idjq7aai9ylm/4fSjj56uD6CYwYyus4KmES/4f6385c91e6de56274d99496e6adebab/EVE_SSO_Login_Buttons_Large_Black.png?w=270&h=45">|]
|
asWidget BigWhite = [whamlet|<img src="https://images.contentful.com/idjq7aai9ylm/4PTzeiAshqiM8osU2giO0Y/5cc4cb60bac52422da2e45db87b6819c/EVE_SSO_Login_Buttons_Large_White.png?w=270&h=45">|]
|
||||||
toWidget SmallWhite = [whamlet|<img src="https://images.contentful.com/idjq7aai9ylm/18BxKSXCymyqY4QKo8KwKe/c2bdded6118472dd587c8107f24104d7/EVE_SSO_Login_Buttons_Small_White.png?w=195&h=30">|]
|
asWidget BigBlack = [whamlet|<img src="https://images.contentful.com/idjq7aai9ylm/4fSjj56uD6CYwYyus4KmES/4f6385c91e6de56274d99496e6adebab/EVE_SSO_Login_Buttons_Large_Black.png?w=270&h=45">|]
|
||||||
toWidget SmallBlack = [whamlet|<img src="https://images.contentful.com/idjq7aai9ylm/12vrPsIMBQi28QwCGOAqGk/33234da7672c6b0cdca394fc8e0b1c2b/EVE_SSO_Login_Buttons_Small_Black.png?w=195&h=30">|]
|
asWidget SmallWhite = [whamlet|<img src="https://images.contentful.com/idjq7aai9ylm/18BxKSXCymyqY4QKo8KwKe/c2bdded6118472dd587c8107f24104d7/EVE_SSO_Login_Buttons_Small_White.png?w=195&h=30">|]
|
||||||
toWidget (Custom a) = a
|
asWidget SmallBlack = [whamlet|<img src="https://images.contentful.com/idjq7aai9ylm/12vrPsIMBQi28QwCGOAqGk/33234da7672c6b0cdca394fc8e0b1c2b/EVE_SSO_Login_Buttons_Small_Black.png?w=195&h=30">|]
|
||||||
|
asWidget (Custom a) = a
|
||||||
|
|
||||||
oauth2EveScoped :: YesodAuth m
|
oauth2EveScoped :: YesodAuth m
|
||||||
=> Text -- ^ Client ID
|
=> Text -- ^ Client ID
|
||||||
-> Text -- ^ Client Secret
|
-> Text -- ^ Client Secret
|
||||||
-> [Text] -- ^ List of scopes to request
|
-> [Text] -- ^ List of scopes to request
|
||||||
-> Maybe (WidgetT m IO ()) -- ^ Login-Widget
|
-> WidgetT m IO () -- ^ Login widget
|
||||||
-> AuthPlugin m
|
-> AuthPlugin m
|
||||||
oauth2EveScoped clientId clientSecret scopes widget =
|
oauth2EveScoped clientId clientSecret scopes widget =
|
||||||
case widget of
|
authOAuth2Widget widget "eveonline" oauth fetchEveProfile
|
||||||
Just w -> authOAuth2Widget "eveonline" oauth fetchEveProfile w
|
|
||||||
Nothing -> authOAuth2 "eveonline" oauth fetchEveProfile
|
|
||||||
where
|
where
|
||||||
oauth = OAuth2
|
oauth = OAuth2
|
||||||
{ oauthClientId = encodeUtf8 clientId
|
{ oauthClientId = encodeUtf8 clientId
|
||||||
@ -110,7 +104,7 @@ fetchEveProfile manager token = do
|
|||||||
Left err-> throwIO $ InvalidProfileResponse "eveonline" err
|
Left err-> throwIO $ InvalidProfileResponse "eveonline" err
|
||||||
|
|
||||||
toCreds :: EveUser -> AccessToken -> Creds m
|
toCreds :: EveUser -> AccessToken -> Creds m
|
||||||
toCreds user token = Creds
|
toCreds user _ = Creds
|
||||||
{ credsPlugin = "eveonline"
|
{ credsPlugin = "eveonline"
|
||||||
, credsIdent = T.pack $ show $ eveCharOwnerHash user
|
, credsIdent = T.pack $ show $ eveCharOwnerHash user
|
||||||
, credsExtra =
|
, credsExtra =
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user