blob: e30b04aaa58e8cae689cb47b6b992ead3ebe02f4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
package testprovider
import (
"time"
"github.com/nsheridan/cashier/server/auth"
"golang.org/x/oauth2"
)
const (
name = "testprovider"
)
// Config is an implementation of `auth.Provider` for testing.
type Config struct{}
var _ auth.Provider = (*Config)(nil)
// New creates a new provider.
func New() *Config {
return &Config{}
}
// Name returns the name of the provider.
func (c *Config) Name() string {
return name
}
// Valid validates the oauth token.
func (c *Config) Valid(token *oauth2.Token) bool {
return true
}
// Revoke disables the access token.
func (c *Config) Revoke(token *oauth2.Token) error {
return nil
}
// StartSession retrieves an authentication endpoint.
func (c *Config) StartSession(state string) *auth.Session {
return &auth.Session{
AuthURL: "https://www.example.com/auth",
}
}
// Exchange authorizes the session and returns an access token.
func (c *Config) Exchange(code string) (*oauth2.Token, error) {
return &oauth2.Token{
AccessToken: "token",
Expiry: time.Now().Add(1 * time.Hour),
}, nil
}
// Username retrieves the username portion of the user's email address.
func (c *Config) Username(token *oauth2.Token) string {
return "test"
}
|