diff --git a/src/GitHub/Auth.hs b/src/GitHub/Auth.hs index ccc2415a..2b41dbf4 100644 --- a/src/GitHub/Auth.hs +++ b/src/GitHub/Auth.hs @@ -1,5 +1,7 @@ module GitHub.Auth ( Auth (..), + Token, + JWTToken, AuthMethod, endpoint, setAuthRequest @@ -9,14 +11,17 @@ import GitHub.Internal.Prelude import Prelude () import qualified Data.ByteString as BS +import qualified Data.Text.Encoding as TE import qualified Network.HTTP.Client as HTTP type Token = BS.ByteString +type JWTToken = Text -- | The Github auth data type data Auth = BasicAuth BS.ByteString BS.ByteString -- ^ Username and password | OAuth Token -- ^ OAuth token + | JWT JWTToken -- ^ JWT Token | EnterpriseOAuth Text Token -- ^ Custom endpoint and OAuth token deriving (Show, Data, Typeable, Eq, Ord, Generic) @@ -40,10 +45,12 @@ instance AuthMethod () where instance AuthMethod Auth where endpoint (BasicAuth _ _) = Nothing endpoint (OAuth _) = Nothing + endpoint (JWT _) = Nothing endpoint (EnterpriseOAuth e _) = Just e setAuthRequest (BasicAuth u p) = HTTP.applyBasicAuth u p setAuthRequest (OAuth t) = setAuthHeader $ "token " <> t + setAuthRequest (JWT t) = setAuthHeader $ "Bearer " <> TE.encodeUtf8 t setAuthRequest (EnterpriseOAuth _ t) = setAuthHeader $ "token " <> t setAuthHeader :: BS.ByteString -> HTTP.Request -> HTTP.Request