@hackage github-app-token0.0.1.2

Generate an installation access token for a GitHub App

GitHub App Token

Hackage Stackage Nightly Stackage LTS CI

Generate an installation access token for a GitHub App

Usage

import Prelude

import Control.Lens ((^?))
import Data.Aeson.Lens
import Data.ByteString.Char8 qualified as BS8
import Data.Text.Encoding (encodeUtf8)
import GitHub.App.Token
import Network.HTTP.Simple
import Network.HTTP.Types.Header (hAccept, hAuthorization, hUserAgent)
import System.Environment

example :: IO ()
example = do
  appId <- AppId . read <$> getEnv "GITHUB_APP_ID"
  privateKey <- PrivateKey . BS8.pack <$> getEnv "GITHUB_PRIVATE_KEY"
  installationId <- InstallationId . read <$> getEnv "GITHUB_INSTALLATION_ID"

  let creds = AppCredentials {appId, privateKey}
  token <- generateInstallationToken creds installationId

  req <- parseRequest "https://api.github.com/repos/freckle/github-app-token"
  resp <- httpLBS
    $ addRequestHeader hAccept "application/json"
    $ addRequestHeader hAuthorization ("Bearer " <> encodeUtf8 token.token)
    $ addRequestHeader hUserAgent "github-app-token/example"
    $ req

  print $ getResponseBody resp ^? key "description" . _String
  -- => Just "Generate an installation token for a GitHub App"

CHANGELOG | LICENSE