LemonAi.Auth.GitHubCopilotOAuth (lemon_ai v0.1.0)

View Source

GitHub Copilot OAuth helpers.

Provides:

  • Device-code login flow (URL + user code) for onboarding
  • Copilot token refresh using stored GitHub OAuth access token
  • Secret payload encoding/decoding

Summary

Functions

Encode OAuth secret payload to JSON.

Run GitHub Copilot OAuth device flow.

Normalize GitHub domain input (company.ghe.com or https://company.ghe.com). Returns hostname or nil for blank/invalid values.

Resolve a usable Copilot API key from a secret value.

Types

login_opt()

@type login_opt() ::
  {:enterprise_domain, String.t() | nil}
  | {:on_auth, (String.t(), String.t() | nil -> any())}
  | {:on_progress, (String.t() -> any())}
  | {:enable_models, boolean()}
  | {:persist_secret, (String.t(), String.t() -> any())}

oauth_secret()

@type oauth_secret() :: %{required(String.t()) => String.t() | integer() | nil}

Functions

encode_secret(secret)

@spec encode_secret(oauth_secret()) :: String.t()

Encode OAuth secret payload to JSON.

login_device_flow(opts \\ [])

@spec login_device_flow([login_opt()]) :: {:ok, oauth_secret()} | {:error, term()}

Run GitHub Copilot OAuth device flow.

Returns an OAuth secret payload map suitable for encode_secret/1.

normalize_domain(input)

@spec normalize_domain(String.t()) :: String.t() | nil

Normalize GitHub domain input (company.ghe.com or https://company.ghe.com). Returns hostname or nil for blank/invalid values.

resolve_api_key_from_secret(secret_name, secret_value, opts \\ [])

Resolve a usable Copilot API key from a secret value.

  • Returns :ignore for non-Copilot-OAuth payloads.
  • Returns {:ok, api_key} for valid payloads (refreshing/persisting when needed).
  • Returns {:error, reason} when payload is Copilot OAuth but unusable.