mirror of
https://github.com/freckle/yesod-auth-oauth2.git
synced 2026-09-11 03:44:57 +02:00
TODO: write detailed commit message / CHANGELOG. Highlights: - The "Provider" abstraction, which leads to - Way tinier definitions, also aided by - Stop fetching full profiles (#71) - Drop GHC < 7.10 support (and CPP) - Extract clarified Dispatch module
25 lines
696 B
Haskell
25 lines
696 B
Haskell
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
module Yesod.Auth.OAuth2.UserId
|
|
( UserId(..)
|
|
, UserIdText(..)
|
|
) where
|
|
|
|
import Data.Aeson
|
|
import Data.Text (Text)
|
|
import Yesod.Auth.OAuth2.Provider (ToIdent(..))
|
|
|
|
-- | Parse-able type to use for responses with an integer @id@ field
|
|
newtype UserId = UserId Int
|
|
deriving ToIdent
|
|
|
|
instance FromJSON UserId where
|
|
parseJSON = withObject "User" $ \o -> UserId <$> o .: "id"
|
|
|
|
-- | Parse-able type to use for responses with a textual @id@ field
|
|
newtype UserIdText = UserIdText Text
|
|
deriving ToIdent
|
|
|
|
instance FromJSON UserIdText where
|
|
parseJSON = withObject "User" $ \o -> UserIdText <$> o .: "id"
|