githubapp

package
v0.9.1-rc.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 10, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package githubapp authenticates GitHub API calls as the *viewing user* via the GitHub App's user-authorization (user-to-server) flow, rather than as the app installation. This means commit data the dashboard surfaces is scoped to what each user can actually see on GitHub — a user with no access to a repo gets a 404, never someone else's private history.

The app itself is identified by GITHUB_APP_CLIENT_ID / GITHUB_APP_CLIENT_SECRET. Tokens are non-expiring user access tokens (the app must have token expiry disabled) and are held in an httpOnly cookie by the caller, never server-side.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthorizeURL

func AuthorizeURL(redirectURI, state string) string

AuthorizeURL builds the GitHub user-authorization redirect the browser is sent to when the user clicks "Connect GitHub". redirectURI must match a callback URL registered on the GitHub App; state is an opaque CSRF token echoed back to the callback. GitHub App user tokens derive access from the app's permissions intersected with the user's — no OAuth scope param is used.

func Configured

func Configured() bool

Configured reports whether the GitHub App user-OAuth env vars are set.

func ExchangeCode

func ExchangeCode(ctx context.Context, code, redirectURI string) (string, error)

ExchangeCode swaps the authorization code from the callback for a user access token, authenticating the exchange with the app's client id + secret.

func ParseRepoURL

func ParseRepoURL(url string) (owner, repo string, ok bool)

ParseRepoURL extracts owner/repo from a GitHub URL in any common form (https://github.com/owner/repo, https://github.com/owner/repo.git, git@github.com:owner/repo.git). Returns ok=false if the URL isn't a recognizable GitHub repo URL.

func UserClient

func UserClient(token string) (*github.Client, error)

UserClient returns a github client that acts as the user who owns token.

⭐ EVERY GET THIS CLIENT MAKES IS CONDITIONAL. `githubcache.Shared()` is the client's transport, so a repeat question carries the stored `ETag` and comes back `304 Not Modified` — which GitHub does not charge to the rate limit — instead of re-downloading a comparison the dashboard already has.

⚠️ THE ORDER OF THESE TWO OPTIONS IS THE SECURITY PROPERTY, not a style choice. go-github's `newClient` installs `WithTransport` first and then wraps it with the token setter, so the cache sees each request WITH its final `Authorization` header and partitions on it. A cache placed above the auth layer would file every user's private answers under one key. See the package comment on `pkg/githubcache`.

Types

type AuthenticatedUser

type AuthenticatedUser struct {
	Login     string `json:"login"`
	AvatarURL string `json:"avatarUrl"`
}

AuthenticatedUser looks up the login + avatar for a token, used to render the connected identity and to validate that a stored token is still good.

func CurrentUser

func CurrentUser(ctx context.Context, token string) (*AuthenticatedUser, error)

CurrentUser calls /user with the token. Returns an error if the token is invalid/revoked, which the caller treats as "not connected".

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL