From 8241ef5e97a407c751449b0724a9cd994afc8df9 Mon Sep 17 00:00:00 2001 From: Andrew Darqui Date: Mon, 20 Jun 2016 02:14:11 -0400 Subject: [PATCH] Properly handle empty "location" fields. --- Yesod/Auth/OAuth2/Github.hs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Yesod/Auth/OAuth2/Github.hs b/Yesod/Auth/OAuth2/Github.hs index 7ffee08..356f678 100644 --- a/Yesod/Auth/OAuth2/Github.hs +++ b/Yesod/Auth/OAuth2/Github.hs @@ -37,7 +37,7 @@ data GithubUser = GithubUser , githubUserName :: Maybe Text , githubUserLogin :: Text , githubUserAvatarUrl :: Text - , githubUserLocation :: Text + , githubUserLocation :: Maybe Text , githubUserPublicEmail :: Maybe Text } @@ -47,8 +47,8 @@ instance FromJSON GithubUser where <*> o .:? "name" <*> o .: "login" <*> o .: "avatar_url" - <*> o .: "location" - <*> o .: "email" + <*> o .:? "location" + <*> o .:? "email" parseJSON _ = mzero @@ -104,11 +104,11 @@ toCreds user userMails token = Creds [ ("email", githubUserEmailAddress email) , ("login", githubUserLogin user) , ("avatar_url", githubUserAvatarUrl user) - , ("location", githubUserLocation user) , ("access_token", decodeUtf8 $ accessToken token) ] ++ maybeName (githubUserName user) ++ maybePublicEmail (githubUserPublicEmail user) + ++ maybeLocation (githubUserLocation user) } where @@ -119,3 +119,6 @@ toCreds user userMails token = Creds maybePublicEmail Nothing = [] maybePublicEmail (Just e) = [("public_email", e)] + + maybeLocation Nothing = [] + maybeLocation (Just location) = [("location", location)]