我正在网站上工作,为了省去私人数据库的麻烦,我决定使用Google API对用户进行身份验证。我按照this指南进行了操作。我复制了代码但是当我运行它并尝试登录时,我会在谷歌屏幕上选择要登录的帐户。我选择了我的帐户,然后它继续加载了很长时间(我离开它半小时没有变化)。此外,该应用程序开始吃我的ram(它使用我16GB的所有东西)。
我不确定它出了什么问题。也许有人以前遇到过这件事?
干杯
编辑: 这是我使用的代码:
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
module Main where
import Data.Default (def)
import Data.Text (Text)
import Network.HTTP.Client.Conduit (Manager, newManager)
import Yesod
import Yesod.Auth
import Yesod.Auth.BrowserId
import Yesod.Auth.GoogleEmail2
clientId :: Text
clientId = "" --Removed it for public view
clientSecret :: Text
clientSecret = "" --Removed it for public view
data App = App
{ httpManager :: Manager
}
mkYesod "App" [parseRoutes|
/ HomeR GET
/auth AuthR Auth getAuth
|]
instance Yesod App where
approot = ApprootStatic "http://localhost:3000"
instance YesodAuth App where
type AuthId App = Text
loginDest _ = HomeR
logoutDest _ = HomeR
authPlugins _ =
[ authGoogleEmail clientId clientSecret
]
authHttpManager = httpManager
maybeAuthId = lookupSession "_ID"
instance RenderMessage App FormMessage where
renderMessage _ _ = defaultFormMessage
getHomeR :: Handler Html
getHomeR = do
maid <- maybeAuthId
defaultLayout
[whamlet|
<p>Your current auth ID: #{show maid}
$maybe _ <- maid
<p>
<a href=@{AuthR LogoutR}>Logout
$nothing
<p>
<a href=@{AuthR LoginR}>Go to the login page
|]
main :: IO ()
main = do
man <- newManager
warp 3000 $ App man
这是来自cabal文件的片段(我使用堆栈来构建可执行文件):
executable App-exe
hs-source-dirs: app
main-is: Main.hs
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends: base
, yesod
, yesod-auth
, text
, http-conduit
, data-default
, OWTeamQueue
default-language: Haskell2010
答案 0 :(得分:0)
问题是我没有在def __init__(self, value):
if not isinstance(value, self.value_type):
raise TypeError
self.value = value
的实例中实现getAuthId
函数。我不确定为什么当我使用堆栈构建它时,这不会显示为错误/警告。