oauth

package
v0.0.0-...-813a201 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2015 License: MPL-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Routes = []routes.Route{
	routes.Route{
		Name:        "oauth_tokens",
		Methods:     []string{"POST"},
		Pattern:     "/tokens",
		HandlerFunc: handleTokens,
	},
}

Routes for the oauth service

Functions

func MigrateAll

func MigrateAll(db *gorm.DB) error

MigrateAll executes all migrations

Types

type AccessToken

type AccessToken struct {
	ID        int64         `gorm:"primary_key"`
	Token     string        `sql:"type:varchar(40);unique;not null"`
	ExpiresAt time.Time     `sql:"not null"`
	Scope     string        `sql:"type:varchar(200);not null"`
	ClientID  sql.NullInt64 `sql:"index;not null"`
	UserID    sql.NullInt64 `sql:"index"`
	Client    *Client
	User      *User
}

AccessToken ...

type AuthorizationCode

type AuthorizationCode struct {
	ID          int64          `gorm:"primary_key"`
	Code        string         `sql:"type:varchar(40);unique;not null"`
	RedirectURI sql.NullString `sql:"type:varchar(200)"`
	ExpiresAt   time.Time      `sql:"not null"`
	Scope       string         `sql:"type:varchar(200);not null"`
	ClientID    sql.NullInt64  `sql:"index;not null"`
	UserID      sql.NullInt64  `sql:"index;not null"`
	Client      *Client
	User        *User
}

AuthorizationCode ...

type Client

type Client struct {
	ID          int64          `gorm:"primary_key"`
	ClientID    string         `sql:"type:varchar(254);unique;not null"`
	Secret      string         `sql:"type:varchar(60);not null"`
	RedirectURI sql.NullString `sql:"type:varchar(200)"`
}

Client ...

type RefreshToken

type RefreshToken struct {
	ID        int64         `gorm:"primary_key"`
	Token     string        `sql:"type:varchar(40);unique;not null"`
	ExpiresAt time.Time     `sql:"not null"`
	Scope     string        `sql:"type:varchar(200);not null"`
	ClientID  sql.NullInt64 `sql:"index;not null"`
	UserID    sql.NullInt64 `sql:"index"`
	Client    *Client
	User      *User
}

RefreshToken ...

type Scope

type Scope struct {
	ID          int64  `gorm:"primary_key"`
	Scope       string `sql:"type:varchar(200);unique;not null"`
	Description sql.NullString
	IsDefault   bool `sql:"default:false"`
}

Scope ...

type Service

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

Service struct keeps config and db objects to avoid passing them around

func GetService

func GetService() *Service

GetService returns internal Service instance

func NewService

func NewService(cnf *config.Config, db *gorm.DB) *Service

NewService starts a new Service instance

func (*Service) AuthClient

func (s *Service) AuthClient(clientID, secret string) (*Client, error)

AuthClient authenticates client

func (*Service) AuthUser

func (s *Service) AuthUser(username, thePassword string) (*User, error)

AuthUser authenticates user

func (*Service) Authenticate

func (s *Service) Authenticate(token string) error

Authenticate checks the access token is valid

func (*Service) CreateClient

func (s *Service) CreateClient(clientID, secret, redirectURI string) (*Client, error)

CreateClient saves a new client to database

func (*Service) CreateUser

func (s *Service) CreateUser(username, thePassword string) (*User, error)

CreateUser saves a new user to database

func (*Service) FindClientByClientID

func (s *Service) FindClientByClientID(clientID string) (*Client, error)

FindClientByClientID looks up a client by client ID

func (*Service) FindUserByUsername

func (s *Service) FindUserByUsername(username string) (*User, error)

FindUserByUsername looks up a user by username

func (*Service) GetOrCreateRefreshToken

func (s *Service) GetOrCreateRefreshToken(client *Client, user *User, scope string) (*RefreshToken, error)

GetOrCreateRefreshToken retrieves an existing refresh token, if expired, the token gets deleted and new refresh token is created

func (*Service) GetScope

func (s *Service) GetScope(requestedScope string) (string, error)

GetScope takes a requested scope and, if it's empty, returns the default scope, if not empty, it validates the requested scope

func (*Service) GetValidRefreshToken

func (s *Service) GetValidRefreshToken(token string, client *Client) (*RefreshToken, error)

GetValidRefreshToken returns a valid non expired refresh token

func (*Service) GrantAccessToken

func (s *Service) GrantAccessToken(client *Client, user *User, scope string) (*AccessToken, error)

GrantAccessToken deletes old tokens and grants a new access token

func (*Service) GrantAuthorizationCode

func (s *Service) GrantAuthorizationCode(client *Client, user *User, redirectURI, scope string) (*AuthorizationCode, error)

GrantAuthorizationCode grants a new authorization code

func (*Service) UserExists

func (s *Service) UserExists(username string) bool

UserExists returns true if user exists

type User

type User struct {
	ID       int64  `gorm:"primary_key"`
	Username string `sql:"type:varchar(254);unique;not null"`
	Password string `sql:"type:varchar(60);not null"`
}

User ...

Jump to

Keyboard shortcuts

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