Documentation
¶
Overview ¶
Package github provides GitHub OAuth integration.
Package github provides GitHub OAuth integration.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrGitHubOAuth indicates a failure in the GitHub OAuth flow. ErrGitHubOAuth = errors.New("GitHub OAuth error") // ErrGitHubAPI indicates a failure calling the GitHub API. ErrGitHubAPI = errors.New("GitHub API error") )
Error sentinels for GitHub OAuth operations.
Functions ¶
func ValidateRedirectURI ¶
ValidateRedirectURI validates a redirect URI for security. Per OAuth 2.1 and MCP spec, redirect URIs must be either: - localhost (http://localhost:*, http://127.0.0.1:*, http://[::1]:*) - HTTPS URLs.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client provides GitHub OAuth operations.
func NewClient ¶
func NewClient(log logrus.FieldLogger, clientID, clientSecret string) *Client
NewClient creates a new GitHub OAuth client.
func (*Client) ExchangeCode ¶
func (c *Client) ExchangeCode(ctx context.Context, code, redirectURI string) (*TokenResponse, error)
ExchangeCode exchanges an authorization code for an access token.
func (*Client) GetAuthorizationURL ¶
GetAuthorizationURL generates the GitHub OAuth authorization URL.
type GitHubUser ¶
type GitHubUser struct {
// ID is the GitHub user ID.
ID int64 `json:"id"`
// Login is the GitHub username.
Login string `json:"login"`
// Name is the user's display name.
Name string `json:"name,omitempty"`
// Email is the user's email address.
Email string `json:"email,omitempty"`
// AvatarURL is the URL to the user's avatar.
AvatarURL string `json:"avatar_url,omitempty"`
// Organizations is a list of organization logins the user belongs to.
Organizations []string `json:"organizations,omitempty"`
}
GitHubUser represents a GitHub user profile.
func (*GitHubUser) IsMemberOf ¶
func (u *GitHubUser) IsMemberOf(allowedOrgs []string) bool
IsMemberOf checks if the user is a member of any of the allowed organizations. If allowedOrgs is empty, returns true (no restriction).
type TokenResponse ¶
type TokenResponse struct {
// AccessToken is the GitHub access token.
AccessToken string `json:"access_token"`
// TokenType is the type of token (usually "bearer").
TokenType string `json:"token_type"`
// Scope contains the granted scopes.
Scope string `json:"scope"`
// Error is set if the request failed.
Error string `json:"error,omitempty"`
// ErrorDescription provides details about the error.
ErrorDescription string `json:"error_description,omitempty"`
}
TokenResponse represents GitHub's OAuth token response.