123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- package auth
- import (
- "time"
- )
- // TokenInfo the token information model interface
- type TokenInfo interface {
- New() TokenInfo
- GetUserID() string
- SetUserID(string)
- GetAccess() string
- SetAccess(string)
- GetAccessCreateAt() time.Time
- SetAccessCreateAt(time.Time)
- GetAccessExpiresIn() time.Duration
- SetAccessExpiresIn(time.Duration)
- GetRefresh() string
- SetRefresh(string)
- GetRefreshCreateAt() time.Time
- SetRefreshCreateAt(time.Time)
- GetRefreshExpiresIn() time.Duration
- SetRefreshExpiresIn(time.Duration)
- }
- // NewToken create to token model instance
- func NewToken() *Token {
- return &Token{}
- }
- // Token token model
- type Token struct {
- UserID string `bson:"UserID"`
- Access string `bson:"Access"`
- AccessCreateAt time.Time `bson:"AccessCreateAt"`
- AccessExpiresIn time.Duration `bson:"AccessExpiresIn"`
- Refresh string `bson:"Refresh"`
- RefreshCreateAt time.Time `bson:"RefreshCreateAt"`
- RefreshExpiresIn time.Duration `bson:"RefreshExpiresIn"`
- }
- // New create to token model instance
- func (t *Token) New() TokenInfo {
- return NewToken()
- }
- // GetUserID the user id
- func (t *Token) GetUserID() string {
- return t.UserID
- }
- // SetUserID the user id
- func (t *Token) SetUserID(userID string) {
- t.UserID = userID
- }
- // GetAccess access Token
- func (t *Token) GetAccess() string {
- return t.Access
- }
- // SetAccess access Token
- func (t *Token) SetAccess(access string) {
- t.Access = access
- }
- // GetAccessCreateAt create Time
- func (t *Token) GetAccessCreateAt() time.Time {
- return t.AccessCreateAt
- }
- // SetAccessCreateAt create Time
- func (t *Token) SetAccessCreateAt(createAt time.Time) {
- t.AccessCreateAt = createAt
- }
- // GetAccessExpiresIn the lifetime in seconds of the access token
- func (t *Token) GetAccessExpiresIn() time.Duration {
- return t.AccessExpiresIn
- }
- // SetAccessExpiresIn the lifetime in seconds of the access token
- func (t *Token) SetAccessExpiresIn(exp time.Duration) {
- t.AccessExpiresIn = exp
- }
- // GetRefresh refresh Token
- func (t *Token) GetRefresh() string {
- return t.Refresh
- }
- // SetRefresh refresh Token
- func (t *Token) SetRefresh(refresh string) {
- t.Refresh = refresh
- }
- // GetRefreshCreateAt create Time
- func (t *Token) GetRefreshCreateAt() time.Time {
- return t.RefreshCreateAt
- }
- // SetRefreshCreateAt create Time
- func (t *Token) SetRefreshCreateAt(createAt time.Time) {
- t.RefreshCreateAt = createAt
- }
- // GetRefreshExpiresIn the lifetime in seconds of the refresh token
- func (t *Token) GetRefreshExpiresIn() time.Duration {
- return t.RefreshExpiresIn
- }
- // SetRefreshExpiresIn the lifetime in seconds of the refresh token
- func (t *Token) SetRefreshExpiresIn(exp time.Duration) {
- t.RefreshExpiresIn = exp
- }
|