workgroups/vendor/github.com/dghubble/oauth1/token.go
Marvin Preuss 1d4ae27878
All checks were successful
continuous-integration/drone/push Build is passing
ci: drone yaml with reusable anchors
2021-09-24 17:34:17 +02:00

44 lines
1.0 KiB
Go

package oauth1
import (
"errors"
)
// A TokenSource can return a Token.
type TokenSource interface {
Token() (*Token, error)
}
// Token is an AccessToken (token credential) which allows a consumer (client)
// to access resources from an OAuth1 provider server.
type Token struct {
Token string
TokenSecret string
}
// NewToken returns a new Token with the given token and token secret.
func NewToken(token, tokenSecret string) *Token {
return &Token{
Token: token,
TokenSecret: tokenSecret,
}
}
// StaticTokenSource returns a TokenSource which always returns the same Token.
// This is appropriate for tokens which do not have a time expiration.
func StaticTokenSource(token *Token) TokenSource {
return staticTokenSource{token}
}
// staticTokenSource is a TokenSource that always returns the same Token.
type staticTokenSource struct {
token *Token
}
func (s staticTokenSource) Token() (*Token, error) {
if s.token == nil {
return nil, errors.New("oauth1: Token is nil")
}
return s.token, nil
}