...

Package github

import "github.com/matrix-org/go-neb/realms/github"
Overview
Index

Overview ▾

Package github implements OAuth2 support for github.com

Constants

const RealmType = "github"

RealmType of the Github Realm

type AuthRequest

type AuthRequest struct {
    // Optional. The URL to redirect to after authentication.
    RedirectURL string
}

AuthRequest is a request for authenticating with github.com

type AuthResponse

type AuthResponse struct {
    // The URL to visit to perform OAuth on github.com
    URL string
}

AuthResponse is a response to an AuthRequest.

type Realm

type Realm struct {

    // The client secret for this Github application.
    ClientSecret string
    // The client ID for this Github application.
    ClientID string
    // Optional. The URL to redirect the client to after authentication.
    StarterLink string
    // contains filtered or unexported fields
}

Realm can handle OAuth processes with github.com

Example request:

{
    "ClientSecret": "YOUR_CLIENT_SECRET",
    "ClientID": "YOUR_CLIENT_ID"
}

func (*Realm) AuthSession

func (r *Realm) AuthSession(id, userID, realmID string) types.AuthSession

AuthSession returns a Github Session for this user

func (*Realm) ID

func (r *Realm) ID() string

ID returns the realm ID

func (*Realm) Init

func (r *Realm) Init() error

Init does nothing.

func (*Realm) OnReceiveRedirect

func (r *Realm) OnReceiveRedirect(w http.ResponseWriter, req *http.Request)

OnReceiveRedirect processes OAuth redirect requests from Github

func (*Realm) Register

func (r *Realm) Register() error

Register does nothing.

func (*Realm) RequestAuthSession

func (r *Realm) RequestAuthSession(userID string, req json.RawMessage) interface{}

RequestAuthSession generates an OAuth2 URL for this user to auth with github via. The request body is of type "github.AuthRequest". The response is of type "github.AuthResponse".

Request example:

{
    "RedirectURL": "https://optional-url.com/to/redirect/to/after/auth"
}

Response example:

{
    "URL": "https://github.com/login/oauth/authorize?client_id=abcdef&client_secret=acascacac...."
}

func (*Realm) Type

func (r *Realm) Type() string

Type is github

type Session

type Session struct {

    // AccessToken is the github access token for the user
    AccessToken string
    // Scopes are the set of *ALLOWED* scopes (which may not be the same as the requested scopes)
    Scopes string
    // Optional. The client-supplied URL to redirect them to after the auth process is complete.
    ClientsRedirectURL string
    // contains filtered or unexported fields
}

Session represents an authenticated github session

func (*Session) Authenticated

func (s *Session) Authenticated() bool

Authenticated returns true if the user has completed the auth process

func (*Session) ID

func (s *Session) ID() string

ID returns the session ID

func (*Session) Info

func (s *Session) Info() interface{}

Info returns a list of possible repositories that this session can integrate with.

func (*Session) RealmID

func (s *Session) RealmID() string

RealmID returns the realm ID of the realm which performed the authentication

func (*Session) UserID

func (s *Session) UserID() string

UserID returns the user_id who authorised with Github