github

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2016 License: BSD-2-Clause Imports: 9 Imported by: 0

Documentation

Overview

Package github provides auth.Authentication and auth.Authorizer implementations backed by GitHub users, orgs and teams.

Index

Constants

View Source
const (
	// HeaderTwoFactor is the HTTP header that github users for two factor
	// authentication.
	//
	// In a request, the value of this header should be the two factor auth
	// code. In a response, the presence of this header indicates that two
	// factor authentication is required for the user. See
	// http://goo.gl/h7al6K for more information.
	HeaderTwoFactor = "X-GitHub-OTP"
)

Variables

View Source
var (
	// DefaultURL is the default location for the GitHub API.
	DefaultURL = "https://api.github.com"
)

Functions

This section is empty.

Types

type Authenticator

type Authenticator struct {
	// contains filtered or unexported fields
}

Authorizer is an implementation of the auth.Authenticator interface backed by GitHub's Non-Web Application Flow, which can be found at http://goo.gl/onpQKM.

func NewAuthenticator

func NewAuthenticator(c *Client) *Authenticator

NewAuthenticator returns a new Authenticator instance that uses the given Client to make calls to GitHub.

func (*Authenticator) Authenticate

func (a *Authenticator) Authenticate(username, password, otp string) (*empire.User, error)

type Authorization

type Authorization struct {
	Token string `json:"token"`
}

Authorization represents a GitHub Authorization. See http://goo.gl/bs9I3o for more information.

type Client

type Client struct {
	// URL for the GitHub API. This can be changed if you're using GitHub
	// Enterprise. The zero value is DefaultURL.
	URL string

	// OAuth configuration.
	*oauth2.Config
	// contains filtered or unexported fields
}

Client is a github client implementation for creating authorizations, and checking organization membership.

func NewClient

func NewClient(config *oauth2.Config) *Client

NewClient returns a new Client instance that uses the given oauth2 config.

func (*Client) CreateAuthorization

func (c *Client) CreateAuthorization(opts CreateAuthorizationOptions) (*Authorization, error)

CreateAuthorization creates a new GitHub authorization (or returns the existing authorization if present) for the GitHub OAuth application. See http://goo.gl/bs9I3o.

func (*Client) Do

func (c *Client) Do(req *http.Request, v interface{}) (*http.Response, error)

func (*Client) GetUser

func (c *Client) GetUser(token string) (*User, error)

GetUser makes an authenticated request to /user and returns the GitHub User.

func (*Client) IsOrganizationMember added in v0.10.1

func (c *Client) IsOrganizationMember(organization, token string) (bool, error)

IsOrganizationMember returns true of the authenticated user is a member of the organization.

func (*Client) IsTeamMember added in v0.10.1

func (c *Client) IsTeamMember(teamID, token string) (bool, error)

IsTeamMember returns true if the given user is a member of the team.

func (*Client) NewRequest

func (c *Client) NewRequest(method, path string, v interface{}) (*http.Request, error)

type CreateAuthorizationOptions

type CreateAuthorizationOptions struct {
	Username string
	Password string
	OTP      string
}

CreateAuthorizationOptions is a set of options used when creating a GitHub authorization.

type OrganizationAuthorizer

type OrganizationAuthorizer struct {
	Organization string
	// contains filtered or unexported fields
}

OrganizationAuthorizer is an implementation of the auth.Authorizer interface that checks that the user is a member of the given GitHub organization.

func NewOrganizationAuthorizer

func NewOrganizationAuthorizer(c *Client) *OrganizationAuthorizer

NewOrganizationAuthorizer returns a new OrganizationAuthorizer instance.

func (*OrganizationAuthorizer) Authorize

func (a *OrganizationAuthorizer) Authorize(user *empire.User) error

type TeamAuthorizer added in v0.10.1

type TeamAuthorizer struct {
	TeamID string
	// contains filtered or unexported fields
}

TeamAuthorizer is an implementation of the auth.Authorizer interface that checks that the user is a member of the given GitHub team.

func NewTeamAuthorizer added in v0.10.1

func NewTeamAuthorizer(c *Client) *TeamAuthorizer

func (*TeamAuthorizer) Authorize added in v0.10.1

func (a *TeamAuthorizer) Authorize(user *empire.User) error

type TeamMembership added in v0.10.1

type TeamMembership struct {
	State string `json:"state"`
}

type User

type User struct {
	Login string `json:"login"`
}

Jump to

Keyboard shortcuts

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