2022-07-28 15:00:43 +00:00
|
|
|
package model
|
|
|
|
|
|
|
|
import (
|
2022-08-10 13:53:34 +00:00
|
|
|
"golang.org/x/oauth2"
|
2022-07-28 15:00:43 +00:00
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Amo struct {
|
2022-08-22 04:23:47 +00:00
|
|
|
ID string `bson:"_id,omitempty"`
|
|
|
|
UserID string `bson:"user_id"`
|
|
|
|
AccountID string `bson:"account_id"` // Account ID in AMO CRM
|
|
|
|
Subdomain string `bson:"subdomain"` // Subdomain in AMO CRM. Example: [subdomain].amocrm.ru/
|
|
|
|
Referer string `bson:"referer"` // Referer in AMO CRM. Example: subdomain.amocrm.ru
|
|
|
|
FromWidget string `bson:"from_widget"`
|
|
|
|
AccessToken string `bson:"access_token"`
|
|
|
|
RefreshToken string `bson:"refresh_token"`
|
|
|
|
Code string `bson:"code"`
|
|
|
|
ExpiresIn time.Time `bson:"expires_in"`
|
|
|
|
TokenType string `bson:"token_type"`
|
|
|
|
AccessRules AmoAccessRules `bson:"access_rules"`
|
|
|
|
IsDeleted bool `bson:"is_deleted"`
|
|
|
|
CreatedAt time.Time `bson:"created_at"`
|
|
|
|
UpdatedAt time.Time `bson:"updated_at"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type AmoAccessRules struct {
|
|
|
|
Visibility []int64 `bson:"visibility"`
|
|
|
|
Creation []int64 `bson:"creation"`
|
|
|
|
Delete []int64 `bson:"delete"`
|
2022-07-28 15:00:43 +00:00
|
|
|
}
|
2022-08-10 13:53:34 +00:00
|
|
|
|
|
|
|
func (m *Amo) Token() *oauth2.Token {
|
|
|
|
token := &oauth2.Token{
|
|
|
|
AccessToken: m.AccessToken,
|
|
|
|
TokenType: m.TokenType,
|
|
|
|
RefreshToken: m.RefreshToken,
|
|
|
|
Expiry: m.ExpiresIn,
|
|
|
|
}
|
|
|
|
|
|
|
|
if !token.Valid() {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return token
|
|
|
|
}
|