tokauth

package module
v0.0.0-...-7e40583 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2014 License: MIT Imports: 6 Imported by: 2

README

tokauth

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	IDFieldName = "_id"
)

Functions

func Authorize

func Authorize(token string) bool

Authorize check if the given token match with the AccessToken of the client.

func GetAccessTokenFromRefreshToken

func GetAccessTokenFromRefreshToken(refreshToken string) (accessToken string, err error)

GetAccessTokenFromRefreshToken returns the accessToken of the user associated by this refreshToken.

func GetRefreshTokenFromAccessToken

func GetRefreshTokenFromAccessToken(accessToken string) (refreshToken string, err error)

GetRefreshTokenFromAccessToken returns the refreshToken of the user associated by this accessToken.

func Refresh

func Refresh(refreshToken string) (accessToken string, err error)

Refresh the AccessData of the user.

func RefreshAndGetClient

func RefreshAndGetClient(refreshToken string, object interface{}) (string, error)

RefreshAndGetClient refreshes the user and returns it.

func Register

func Register(id interface{}) (refreshToken, accessToken string, err error)

Register a new client. The client must exists in the collection given via the function SetClientCollection. The ID parameter is the ID of the client that needs to be registered.

func SetAccessCollection

func SetAccessCollection(collection *mgo.Collection)

SetAccessCollection sets the collection used to store the AccessData. By default, the AccessToken expiration is set to 10 minutes, to changes it, call SetTokenExpiration before this function.

func SetClientCollection

func SetClientCollection(collection *mgo.Collection)

SetClientCollection sets the collection used to query the clientID (clientID must be the "_id" of the collection).

func SetRemainingTime

func SetRemainingTime(accessToken string, date time.Time) (err error)

SetRemainingTime set the new date at which the token will expires.

func SetTokenExpiration

func SetTokenExpiration(expiration time.Duration)

SetTokenExpiration set a new token duration (by default it is set to 10 minutes). This function must be called before SetClientCollection to have any effect.

Types

type Client

type Client struct {
	RefreshToken string `json:"refreshToken,omitempty" bson:"refreshToken"`
	AccessToken  string `json:"accessToken,omitempty" bson:"-"`
}

Client is a simple struct with a RefreshToken field. This struct has to be embedded by the struct populating the Client Collection set by the user.

Jump to

Keyboard shortcuts

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