Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

make logout work

  • Loading branch information...
commit fa963c008b8ca6f8a2ce34459f9b0da1524eba5b 1 parent 5f52098
@timjb authored
View
8 Foundation.hs
@@ -4,7 +4,7 @@ import Prelude
import Yesod
import Yesod.Static
import Yesod.Auth
-import GoogleOAuth2 (googleOAuth2, AccessToken (..), forwardR)
+import GoogleOAuth2 (googleOAuth2, AccessToken (..), forwardR, revokeAccessToken)
import Yesod.Default.Config
import Yesod.Default.Util (addStaticContentExternal)
import Network.HTTP.Conduit (Manager, Response (..))
@@ -177,6 +177,12 @@ instance YesodAuth App where
, "https://www.googleapis.com/auth/drive.install"
, "https://www.googleapis.com/auth/userinfo.profile"
]
+
+ onLogout = do
+ mAccessToken <- maybeAccessToken
+ case mAccessToken of
+ Nothing -> return ()
+ Just at -> liftIO $ revokeAccessToken at
authHttpManager = httpManager
View
6 GoogleOAuth2.hs
@@ -5,6 +5,7 @@ module GoogleOAuth2
, callbackR
, getGoogleCreds
, googleOAuth2
+ , revokeAccessToken
) where
import Prelude
@@ -25,6 +26,7 @@ import qualified Google.Oauth2.V2 as Oauth2
import qualified Google.Oauth2.V2.Types as Oauth2T
import Data.Maybe (catMaybes)
import Helpers (conduitAeson)
+import Control.Monad (void)
data GoogleOAuth2Settings = GoogleOAuth2Settings
@@ -128,3 +130,7 @@ googleOAuth2 gOAuth scopes = AuthPlugin name dispatch login
login tm = do
render <- lift getUrlRender
[whamlet|<p><a href="#{render $ tm forwardR}">Log in with Google</a>|]
+
+revokeAccessToken :: AccessToken -> IO ()
+revokeAccessToken (AccessToken at) = void $ simpleHttp $ unpack url
+ where url = "https://accounts.google.com/o/oauth2/revoke?token=" <> at
View
2  templates/default-layout.hamlet
@@ -13,7 +13,7 @@
<b.caret>
<ul.dropdown-menu>
<li><a target="_blank" href="https://drive.google.com">Google Drive</a>
- <li><a href="#">Log out</a>
+ <li><a href="@{AuthR LogoutR}">Log out</a>
$nothing
<li><a href="@{AuthR forwardR}">Log in with Google Drive</a>
Please sign in to comment.
Something went wrong with that request. Please try again.