package amo import ( "errors" "github.com/dgrijalva/jwt-go" "time" ) type RespAuthCode struct { TokenType string `json:"token_type"` ExpiresIn int64 `json:"expires_in"` AccessToken string `json:"access_token"` RefreshToken string `json:"refresh_token"` } type Lead struct { Id int `json:"id"` Name string `json:"name"` Price int `json:"price"` ResponsibleUserId int `json:"responsible_user_id"` GroupId int `json:"group_id"` StatusId int `json:"status_id"` PipelineId int `json:"pipeline_id"` LossReasonId int `json:"loss_reason_id"` SourceId interface{} `json:"source_id"` CreatedBy int `json:"created_by"` UpdatedBy int `json:"updated_by"` CreatedAt int `json:"created_at"` UpdatedAt int `json:"updated_at"` ClosedAt int `json:"closed_at"` ClosestTaskAt interface{} `json:"closest_task_at"` IsDeleted bool `json:"is_deleted"` CustomFieldsValues []CustomField `json:"custom_fields_values"` Score interface{} `json:"score"` AccountId int `json:"account_id"` IsPriceModifiedByRobot bool `json:"is_price_modified_by_robot"` Links Links `json:"_links"` Embedded struct { Tags []Tags `json:"tags"` CatalogElements []CatalogElement `json:"catalog_elements"` LossReason []LossReason `json:"loss_reason"` Companies []Company `json:"companies"` Contacts []Contact `json:"contacts"` } `json:"_embedded"` } type CustomField struct { FieldId int `json:"field_id"` FieldName string `json:"field_name"` FieldCode interface{} `json:"field_code"` FieldType string `json:"field_type"` Values []struct { Value string `json:"value"` } `json:"values"` IsComputed bool `json:"is_computed"` } type Tags struct { Id int `json:"id"` Name string `json:"name"` Color interface{} `json:"color"` } type Contact struct { Id int `json:"id"` Name string `json:"name"` FirstName string `json:"first_name"` LastName string `json:"last_name"` ResponsibleUserId int `json:"responsible_user_id"` GroupId int `json:"group_id"` CreatedBy int `json:"created_by"` UpdatedBy int `json:"updated_by"` CreatedAt int `json:"created_at"` UpdatedAt int `json:"updated_at"` ClosestTaskAt interface{} `json:"closest_task_at"` CustomFieldsValues []CustomField `json:"custom_fields_values"` AccountId int `json:"account_id"` Links Links `json:"_links"` Embedded struct { Tags []Tags `json:"tags"` Leads []Lead `json:"leads"` Customers []Customer `json:"customers"` CatalogElements []CatalogElement `json:"catalog_elements"` Companies []Company `json:"companies"` } `json:"_embedded"` } type Company struct { Id int `json:"id"` Name string `json:"name"` ResponsibleUserId int `json:"responsible_user_id"` GroupId int `json:"group_id"` CreatedBy int `json:"created_by"` UpdatedBy int `json:"updated_by"` CreatedAt int `json:"created_at"` UpdatedAt int `json:"updated_at"` ClosestTaskAt interface{} `json:"closest_task_at"` CustomFieldsValues []CustomField `json:"custom_fields_values"` AccountId int `json:"account_id"` Links Links `json:"_links"` Embedded struct { Tags []Tags `json:"tags"` } `json:"_embedded"` } type Customer struct { Id int `json:"id"` Links Links `json:"_links"` } type LossReason struct { Id int `json:"id"` Name string `json:"name"` Sort int `json:"sort"` CreatedAt int `json:"created_at"` UpdatedAt int `json:"updated_at"` Links Links `json:"_links"` } type CatalogElement struct { Id int `json:"id"` Metadata struct { Quantity int `json:"quantity"` CatalogId int `json:"catalog_id"` } `json:"metadata"` } type Links struct { Self struct { Href string `json:"href"` } `json:"self"` } type Account struct { Id int64 `json:"id"` Name string `json:"name"` Subdomain string `json:"subdomain"` CreatedAt int `json:"created_at"` CreatedBy int `json:"created_by"` UpdatedAt int `json:"updated_at"` UpdatedBy int `json:"updated_by"` CurrentUserId int `json:"current_user_id"` Country string `json:"country"` CustomersMode string `json:"customers_mode"` IsUnsortedOn bool `json:"is_unsorted_on"` IsLossReasonEnabled bool `json:"is_loss_reason_enabled"` IsHelpbotEnabled bool `json:"is_helpbot_enabled"` IsTechnicalAccount bool `json:"is_technical_account"` ContactNameDisplayOrder int `json:"contact_name_display_order"` AmojoId string `json:"amojo_id"` Uuid string `json:"uuid"` Version int `json:"version"` Links Links `json:"_links"` Embedded struct { AmojoRights struct { CanDirect bool `json:"can_direct"` CanCreateGroups bool `json:"can_create_groups"` } `json:"amojo_rights"` UsersGroups []struct { Id int `json:"id"` Name string `json:"name"` Uuid interface{} `json:"uuid"` } `json:"users_groups"` TaskTypes []struct { Id int `json:"id"` Name string `json:"name"` Color interface{} `json:"color"` IconId interface{} `json:"icon_id"` Code string `json:"code"` } `json:"task_types"` EntityNames struct { Leads struct { Ru struct { Gender string `json:"gender"` PluralForm struct { Dative string `json:"dative"` Default string `json:"default"` Genitive string `json:"genitive"` Accusative string `json:"accusative"` Instrumental string `json:"instrumental"` Prepositional string `json:"prepositional"` } `json:"plural_form"` SingularForm struct { Dative string `json:"dative"` Default string `json:"default"` Genitive string `json:"genitive"` Accusative string `json:"accusative"` Instrumental string `json:"instrumental"` Prepositional string `json:"prepositional"` } `json:"singular_form"` } `json:"ru"` En struct { SingularForm struct { Default string `json:"default"` } `json:"singular_form"` PluralForm struct { Default string `json:"default"` } `json:"plural_form"` Gender string `json:"gender"` } `json:"en"` Es struct { SingularForm struct { Default string `json:"default"` } `json:"singular_form"` PluralForm struct { Default string `json:"default"` } `json:"plural_form"` Gender string `json:"gender"` } `json:"es"` } `json:"leads"` } `json:"entity_names"` DatetimeSettings struct { DatePattern string `json:"date_pattern"` ShortDatePattern string `json:"short_date_pattern"` ShortTimePattern string `json:"short_time_pattern"` DateFormant string `json:"date_formant"` TimeFormat string `json:"time_format"` Timezone string `json:"timezone"` TimezoneOffset string `json:"timezone_offset"` } `json:"datetime_settings"` } `json:"_embedded"` } // XAuthToken - Одноразовый токен передаваемый в заголовке запроса, при использовании this.$authorizedAjax(). // // Заголовок запроса: x-auth-token // // Алгоритм подписи токена: HS256, в качестве ключа используется secret_key интеграции type XAuthToken struct { Iss string `json:"iss"` // Адрес аккаунта Aud string `json:"aud"` // Базовый адрес, сформированный исходя из значения redirect_uri в интеграции Jti string `json:"jti"` // UUID токена Iat int64 `json:"iat"` // Timestamp, когда был выдан токен Nbf int64 `json:"nbf"` // Timestamp, когда токен начинает действовать Exp int64 `json:"exp"` // Timestamp, когда токен будет просрочен AccountId int64 `json:"account_id"` // ID аккаунта, из которого был сделан запрос Subdomain string `json:"subdomain"` // Субдомен, из которого был сделан запрос ClientUuid string `json:"client_uuid"` // UUID интеграции, // которая сделала запрос UserId int64 `json:"user_id"` // ID пользователя, из под которого был сделан запрос IsAdmin bool `json:"is_admin"` // Является ли пользователь админом jwt.Claims } func (t *XAuthToken) Valid() error { now := time.Now().Unix() //if now >= t.Nbf && now <= t.Exp { // return nil //} if now <= t.Exp { return nil } return errors.New("invalid token") }