Skip to content

Commit 63a4e0c

Browse files
Tom Sydney Kerckhoveandreasabel
authored andcommitted
Allow JWT as an authentication method, fixes #489
1 parent 2bed394 commit 63a4e0c

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/GitHub/Auth.hs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
module GitHub.Auth (
22
Auth (..),
3+
Token,
4+
JWTToken,
35
AuthMethod,
46
endpoint,
57
setAuthRequest
@@ -9,14 +11,17 @@ import GitHub.Internal.Prelude
911
import Prelude ()
1012

1113
import qualified Data.ByteString as BS
14+
import qualified Data.Text.Encoding as TE
1215
import qualified Network.HTTP.Client as HTTP
1316

1417
type Token = BS.ByteString
18+
type JWTToken = Text
1519

1620
-- | The Github auth data type
1721
data Auth
1822
= BasicAuth BS.ByteString BS.ByteString -- ^ Username and password
1923
| OAuth Token -- ^ OAuth token
24+
| JWT JWTToken -- ^ JWT Token
2025
| EnterpriseOAuth Text Token -- ^ Custom endpoint and OAuth token
2126
deriving (Show, Data, Typeable, Eq, Ord, Generic)
2227

@@ -40,10 +45,12 @@ instance AuthMethod () where
4045
instance AuthMethod Auth where
4146
endpoint (BasicAuth _ _) = Nothing
4247
endpoint (OAuth _) = Nothing
48+
endpoint (JWT _) = Nothing
4349
endpoint (EnterpriseOAuth e _) = Just e
4450

4551
setAuthRequest (BasicAuth u p) = HTTP.applyBasicAuth u p
4652
setAuthRequest (OAuth t) = setAuthHeader $ "token " <> t
53+
setAuthRequest (JWT t) = setAuthHeader $ "Bearer " <> TE.encodeUtf8 t
4754
setAuthRequest (EnterpriseOAuth _ t) = setAuthHeader $ "token " <> t
4855

4956
setAuthHeader :: BS.ByteString -> HTTP.Request -> HTTP.Request

0 commit comments

Comments
 (0)