-
Notifications
You must be signed in to change notification settings - Fork 5
/
config.go
37 lines (30 loc) · 1.14 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright 2021 Beat Research B.V. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package app implements GitHub App authentication.
// See: https://docs.github.com/en/free-pro-team@latest/developers/apps/authenticating-with-github-apps#authenticating-as-a-github-app
package app
import (
"crypto/rsa"
"net/http"
"time"
"github.com/beatlabs/github-auth/app/inst"
"github.com/beatlabs/github-auth/jwt"
)
// Config defines the base GitHub App Config structure.
type Config struct {
jwt jwt.JWT
}
// NewConfig returns a new GitHub App instance.
func NewConfig(id string, key *rsa.PrivateKey) (*Config, error) {
return &Config{jwt: jwt.JWT{AppID: id, PrivateKey: key, Expires: time.Minute * 10}}, nil
}
// Client returns an HTTP client with an HTTP transport that adds Authorization headers.
//
func (c *Config) Client() *http.Client {
return c.jwt.Client()
}
// InstallationConfig returns the Installation Config for the provided installation ID.
func (c *Config) InstallationConfig(id string) (*inst.Config, error) {
return inst.NewConfig(c.jwt.AppID, id, c.jwt.PrivateKey)
}