mirror of
https://github.com/commercialhaskell/stackage-server.git
synced 2026-01-11 19:58:28 +01:00
Google OAuth authentication #40
This commit is contained in:
parent
a2697b1e27
commit
b0e2fbf782
@ -6,7 +6,7 @@ import Data.Slug (safeMakeSlug, HasGenIO (getGenIO), randomSlug, Slug,
|
||||
import qualified Database.Persist
|
||||
import Model
|
||||
import qualified Settings
|
||||
import Settings (widgetFile, Extra (..))
|
||||
import Settings (widgetFile, Extra (..), GoogleAuth (..))
|
||||
import Settings.Development (development)
|
||||
import Settings.StaticFiles
|
||||
import qualified System.Random.MWC as MWC
|
||||
@ -15,7 +15,7 @@ import Text.Jasmine (minifym)
|
||||
import Types
|
||||
import Yesod.Auth
|
||||
import Yesod.Auth.BrowserId
|
||||
import Yesod.Auth.GoogleEmail
|
||||
import Yesod.Auth.GoogleEmail2
|
||||
import Yesod.Core.Types (Logger, GWData)
|
||||
import Yesod.Default.Config
|
||||
import Yesod.Default.Util (addStaticContentExternal)
|
||||
@ -218,7 +218,13 @@ instance YesodAuth App where
|
||||
Just _ -> getHandle (cnt + 1)
|
||||
|
||||
-- You can add other plugins like BrowserID, email or OAuth here
|
||||
authPlugins _ = [authBrowserId def, authGoogleEmail]
|
||||
authPlugins app =
|
||||
authBrowserId def : google
|
||||
where
|
||||
google =
|
||||
case googleAuth $ appExtra $ settings app of
|
||||
Nothing -> []
|
||||
Just GoogleAuth {..} -> [authGoogleEmail gaClientId gaClientSecret]
|
||||
|
||||
authHttpManager = httpManager
|
||||
instance YesodAuthPersist App
|
||||
|
||||
12
Settings.hs
12
Settings.hs
@ -68,6 +68,7 @@ data Extra = Extra
|
||||
{ storeConfig :: !BlobStoreConfig
|
||||
, hackageRoot :: !HackageRoot
|
||||
, adminUsers :: !(HashSet Text)
|
||||
, googleAuth :: !(Maybe GoogleAuth)
|
||||
}
|
||||
deriving Show
|
||||
|
||||
@ -76,6 +77,7 @@ parseExtra _ o = Extra
|
||||
<$> o .: "blob-store"
|
||||
<*> (HackageRoot <$> o .: "hackage-root")
|
||||
<*> o .:? "admin-users" .!= mempty
|
||||
<*> o .:? "google-auth"
|
||||
|
||||
data BlobStoreConfig = BSCFile !FilePath
|
||||
| BSCAWS !FilePath !Text !Text !Text !Text
|
||||
@ -95,3 +97,13 @@ instance FromJSON BlobStoreConfig where
|
||||
<*> o .: "secret"
|
||||
<*> o .: "bucket"
|
||||
<*> o .:? "prefix" .!= ""
|
||||
|
||||
data GoogleAuth = GoogleAuth
|
||||
{ gaClientId :: !Text
|
||||
, gaClientSecret :: !Text
|
||||
}
|
||||
deriving Show
|
||||
instance FromJSON GoogleAuth where
|
||||
parseJSON = withObject "GoogleAuth" $ \o -> GoogleAuth
|
||||
<$> o .: "client-id"
|
||||
<*> o .: "client-secret"
|
||||
|
||||
@ -5,6 +5,9 @@ Default: &defaults
|
||||
hackage-root: http://hackage.fpcomplete.com
|
||||
admin-users:
|
||||
- fpcomplete
|
||||
# google-auth:
|
||||
# client-id: foo
|
||||
# client-secret: bar
|
||||
|
||||
Development:
|
||||
<<: *defaults
|
||||
|
||||
Loading…
Reference in New Issue
Block a user