aboutsummaryrefslogtreecommitdiff
path: root/src/Sproxy/Application/OAuth2/LinkedIn.hs
diff options
context:
space:
mode:
authorIgor Pashev <pashev.igor@gmail.com>2016-11-25 23:40:29 +0300
committerIgor Pashev <pashev.igor@gmail.com>2016-11-25 23:51:25 +0300
commitea17e9c2a3350ba670f95a6fa0ce7716adfa4176 (patch)
tree1cde3e92d68a816a54ea7b0cca8af0b97e7c291e /src/Sproxy/Application/OAuth2/LinkedIn.hs
parent7ba0b2158124bbf10fbdeeec70fb7e631a32a364 (diff)
downloadsproxy2-ea17e9c2a3350ba670f95a6fa0ce7716adfa4176.tar.gz
Make sure all HTTP headers are UTF8-encoded
Especially X-Family-Name, X-Given-Name. Since we get all the data from JSON and JSON is in UTF8 by default RFC 7159, we are safe. Refactored to make it less error-prone and to get as small number of encoding/decoding as possible.
Diffstat (limited to 'src/Sproxy/Application/OAuth2/LinkedIn.hs')
-rw-r--r--src/Sproxy/Application/OAuth2/LinkedIn.hs19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/Sproxy/Application/OAuth2/LinkedIn.hs b/src/Sproxy/Application/OAuth2/LinkedIn.hs
index b60afde..b35c566 100644
--- a/src/Sproxy/Application/OAuth2/LinkedIn.hs
+++ b/src/Sproxy/Application/OAuth2/LinkedIn.hs
@@ -7,15 +7,16 @@ module Sproxy.Application.OAuth2.LinkedIn (
import Control.Applicative (empty)
import Control.Exception (Exception, throwIO)
import Data.Aeson (FromJSON, decode, parseJSON, Value(Object), (.:))
-import Data.ByteString.Char8 (pack)
import Data.ByteString.Lazy (ByteString)
import Data.Monoid ((<>))
+import Data.Text (Text)
+import Data.Text.Encoding (encodeUtf8)
import Data.Typeable (Typeable)
import Network.HTTP.Types (hContentType)
import Network.HTTP.Types.URI (urlEncode)
import qualified Network.HTTP.Conduit as H
-import Sproxy.Application.Cookie (AuthUser(..))
+import Sproxy.Application.Cookie (newUser, setFamilyName, setGivenName)
import Sproxy.Application.OAuth2.Common (AccessTokenBody(accessToken), OAuth2Client(..), OAuth2Provider)
@@ -50,14 +51,14 @@ provider (client_id, client_secret) =
Just atResp -> do
let ureq = (H.parseRequest_ "https://api.linkedin.com/v1/people/\
\~:(email-address,first-name,last-name)?format=json") {
- H.requestHeaders = [ ("Authorization", "Bearer " <> pack (accessToken atResp)) ]
+ H.requestHeaders = [ ("Authorization", "Bearer " <> encodeUtf8 (accessToken atResp)) ]
}
uresp <- H.httpLbs ureq mgr
case decode $ H.responseBody uresp of
Nothing -> throwIO $ LinkedInException uresp
- Just u -> return AuthUser { auEmail = emailAddress u
- , auGivenName = firstName u
- , auFamilyName = lastName u }
+ Just u -> return $ setFamilyName (lastName u) $
+ setGivenName (firstName u) $
+ newUser (emailAddress u)
}
@@ -69,9 +70,9 @@ instance Exception LinkedInException
data LinkedInUserInfo = LinkedInUserInfo {
- emailAddress :: String
-, firstName :: String
-, lastName :: String
+ emailAddress :: Text
+, firstName :: Text
+, lastName :: Text
} deriving (Eq, Show)
instance FromJSON LinkedInUserInfo where