diff options
author | Wim <wim@42.be> | 2016-04-10 23:39:38 +0200 |
---|---|---|
committer | Wim <wim@42.be> | 2016-04-10 23:39:38 +0200 |
commit | de4c7804101a47a01d0c9b88ea34d2b153e2b6b9 (patch) | |
tree | fa379bc2e706951a913e0c7009d9906e42363655 /vendor/github.com/mattermost/platform/model/access.go | |
parent | 6b18257185b1830bd2eff83fae30bdd2055f78b0 (diff) | |
download | matterbridge-msglm-de4c7804101a47a01d0c9b88ea34d2b153e2b6b9.tar.gz matterbridge-msglm-de4c7804101a47a01d0c9b88ea34d2b153e2b6b9.tar.bz2 matterbridge-msglm-de4c7804101a47a01d0c9b88ea34d2b153e2b6b9.zip |
Vendor libs
Diffstat (limited to 'vendor/github.com/mattermost/platform/model/access.go')
-rw-r--r-- | vendor/github.com/mattermost/platform/model/access.go | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/vendor/github.com/mattermost/platform/model/access.go b/vendor/github.com/mattermost/platform/model/access.go new file mode 100644 index 00000000..877b3c4f --- /dev/null +++ b/vendor/github.com/mattermost/platform/model/access.go @@ -0,0 +1,93 @@ +// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +package model + +import ( + "encoding/json" + "io" +) + +const ( + ACCESS_TOKEN_GRANT_TYPE = "authorization_code" + ACCESS_TOKEN_TYPE = "bearer" + REFRESH_TOKEN_GRANT_TYPE = "refresh_token" +) + +type AccessData struct { + AuthCode string `json:"auth_code"` + Token string `json:"token"` + RefreshToken string `json:"refresh_token"` + RedirectUri string `json:"redirect_uri"` +} + +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"` +} + +// IsValid validates the AccessData and returns an error if it isn't configured +// correctly. +func (ad *AccessData) IsValid() *AppError { + + if len(ad.AuthCode) == 0 || len(ad.AuthCode) > 128 { + return NewLocAppError("AccessData.IsValid", "model.access.is_valid.auth_code.app_error", nil, "") + } + + if len(ad.Token) != 26 { + return NewLocAppError("AccessData.IsValid", "model.access.is_valid.access_token.app_error", nil, "") + } + + if len(ad.RefreshToken) > 26 { + return NewLocAppError("AccessData.IsValid", "model.access.is_valid.refresh_token.app_error", nil, "") + } + + if len(ad.RedirectUri) > 256 { + return NewLocAppError("AccessData.IsValid", "model.access.is_valid.redirect_uri.app_error", nil, "") + } + + return nil +} + +func (ad *AccessData) ToJson() string { + b, err := json.Marshal(ad) + if err != nil { + return "" + } else { + return string(b) + } +} + +func AccessDataFromJson(data io.Reader) *AccessData { + decoder := json.NewDecoder(data) + var ad AccessData + err := decoder.Decode(&ad) + if err == nil { + return &ad + } else { + return nil + } +} + +func (ar *AccessResponse) ToJson() string { + b, err := json.Marshal(ar) + if err != nil { + return "" + } else { + return string(b) + } +} + +func AccessResponseFromJson(data io.Reader) *AccessResponse { + decoder := json.NewDecoder(data) + var ar AccessResponse + err := decoder.Decode(&ar) + if err == nil { + return &ar + } else { + return nil + } +} |