summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/mattermost/mattermost-server/v6/model/access.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2021-10-16 23:11:32 +0200
committerWim <wim@42.be>2021-10-16 23:23:24 +0200
commit20f6c05ec50739d31f4dbe9fde0d223f2c43f6e8 (patch)
tree230edca06449a8d1755f08aabf45a03e07e6f17c /vendor/github.com/mattermost/mattermost-server/v6/model/access.go
parent57fce93af7f64f025cec6f3ed6088163086bc9fe (diff)
downloadmatterbridge-msglm-20f6c05ec50739d31f4dbe9fde0d223f2c43f6e8.tar.gz
matterbridge-msglm-20f6c05ec50739d31f4dbe9fde0d223f2c43f6e8.tar.bz2
matterbridge-msglm-20f6c05ec50739d31f4dbe9fde0d223f2c43f6e8.zip
Update vendor
Diffstat (limited to 'vendor/github.com/mattermost/mattermost-server/v6/model/access.go')
-rw-r--r--vendor/github.com/mattermost/mattermost-server/v6/model/access.go72
1 files changed, 72 insertions, 0 deletions
diff --git a/vendor/github.com/mattermost/mattermost-server/v6/model/access.go b/vendor/github.com/mattermost/mattermost-server/v6/model/access.go
new file mode 100644
index 00000000..f17c8fbe
--- /dev/null
+++ b/vendor/github.com/mattermost/mattermost-server/v6/model/access.go
@@ -0,0 +1,72 @@
+// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
+// See LICENSE.txt for license information.
+
+package model
+
+import (
+ "net/http"
+)
+
+const (
+ AccessTokenGrantType = "authorization_code"
+ AccessTokenType = "bearer"
+ RefreshTokenGrantType = "refresh_token"
+)
+
+type AccessData struct {
+ ClientId string `json:"client_id"`
+ UserId string `json:"user_id"`
+ Token string `json:"token"`
+ RefreshToken string `json:"refresh_token"`
+ RedirectUri string `json:"redirect_uri"`
+ ExpiresAt int64 `json:"expires_at"`
+ Scope string `json:"scope"`
+}
+
+type AccessResponse struct {
+ AccessToken string `json:"access_token"`
+ TokenType string `json:"token_type"`
+ ExpiresIn int32 `json:"expires_in"`
+ Scope string `json:"scope"`
+ RefreshToken string `json:"refresh_token"`
+ IdToken string `json:"id_token"`
+}
+
+// IsValid validates the AccessData and returns an error if it isn't configured
+// correctly.
+func (ad *AccessData) IsValid() *AppError {
+ if ad.ClientId == "" || len(ad.ClientId) > 26 {
+ return NewAppError("AccessData.IsValid", "model.access.is_valid.client_id.app_error", nil, "", http.StatusBadRequest)
+ }
+
+ if ad.UserId == "" || len(ad.UserId) > 26 {
+ return NewAppError("AccessData.IsValid", "model.access.is_valid.user_id.app_error", nil, "", http.StatusBadRequest)
+ }
+
+ if len(ad.Token) != 26 {
+ return NewAppError("AccessData.IsValid", "model.access.is_valid.access_token.app_error", nil, "", http.StatusBadRequest)
+ }
+
+ if len(ad.RefreshToken) > 26 {
+ return NewAppError("AccessData.IsValid", "model.access.is_valid.refresh_token.app_error", nil, "", http.StatusBadRequest)
+ }
+
+ if ad.RedirectUri == "" || len(ad.RedirectUri) > 256 || !IsValidHTTPURL(ad.RedirectUri) {
+ return NewAppError("AccessData.IsValid", "model.access.is_valid.redirect_uri.app_error", nil, "", http.StatusBadRequest)
+ }
+
+ return nil
+}
+
+func (ad *AccessData) IsExpired() bool {
+
+ if ad.ExpiresAt <= 0 {
+ return false
+ }
+
+ if GetMillis() > ad.ExpiresAt {
+ return true
+ }
+
+ return false
+}