2023-11-04 18:52:41 -04:00
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
2023-11-12 20:01:58 -05:00
|
|
|
|
|
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
2023-11-04 18:52:41 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
type OauthCredential struct {
|
|
|
|
AccessToken string `bson:"access_token,omitempty" json:"access_token,omitempty"`
|
|
|
|
ExpiresIn int `bson:"expires_in,omitempty" json:"expires_in,omitempty"`
|
|
|
|
ExpiresAt time.Time `bson:"expires_at,omitempty" json:"expires_at,omitempty"`
|
|
|
|
TokenType string `bson:"token_type,omitempty" json:"token_type,omitempty"`
|
|
|
|
Scope string `bson:"scope,omitempty" json:"scope,omitempty"`
|
|
|
|
RefreshToken string `bson:"refresh_token,omitempty" json:"refresh_token,omitempty"`
|
|
|
|
}
|
|
|
|
|
2023-11-12 20:01:58 -05:00
|
|
|
const TOKEN_LOCK_TYPE = "token_lock"
|
|
|
|
|
|
|
|
type TokenLock struct {
|
|
|
|
*CommonFields `bson:"obj_info"`
|
|
|
|
Id primitive.ObjectID `bson:"_id"`
|
|
|
|
VendorId primitive.ObjectID `bson:"vendor_id"`
|
|
|
|
TokenId string `bson:"token_id"`
|
|
|
|
Refreshed bool `bson:"refreshed"`
|
2023-11-04 18:52:41 -04:00
|
|
|
}
|
|
|
|
|
2023-11-12 20:01:58 -05:00
|
|
|
func (tl *TokenLock) MongoId() primitive.ObjectID {
|
|
|
|
|
|
|
|
if tl.Id.IsZero() {
|
|
|
|
now := time.Now()
|
|
|
|
tl.Id = primitive.NewObjectIDFromTimestamp(now)
|
|
|
|
}
|
2023-11-04 18:52:41 -04:00
|
|
|
|
2023-11-12 20:01:58 -05:00
|
|
|
return tl.Id
|
|
|
|
}
|
|
|
|
|
|
|
|
func (tl *TokenLock) UpdateObjectInfo() {
|
|
|
|
now := time.Now()
|
|
|
|
if tl.CommonFields == nil {
|
|
|
|
tl.CommonFields = new(CommonFields)
|
|
|
|
tl.EntityType = TOKEN_LOCK_TYPE
|
|
|
|
tl.CreatedAt = now
|
|
|
|
}
|
|
|
|
tl.UpdatedAt = now
|
|
|
|
}
|