forked from influxdata/influxdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.go
51 lines (40 loc) · 1.46 KB
/
auth.go
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
package mocks
import (
"context"
"net/http"
"github.com/influxdata/influxdb/chronograf/oauth2"
)
// Authenticator implements a OAuth2 authenticator
type Authenticator struct {
Principal oauth2.Principal
ValidateErr error
ExtendErr error
Serialized string
}
// Validate returns Principal associated with authenticated and authorized
// entity if successful.
func (a *Authenticator) Validate(context.Context, *http.Request) (oauth2.Principal, error) {
return a.Principal, a.ValidateErr
}
// Extend will extend the lifetime of a already validated Principal
func (a *Authenticator) Extend(ctx context.Context, w http.ResponseWriter, p oauth2.Principal) (oauth2.Principal, error) {
cookie := http.Cookie{}
http.SetCookie(w, &cookie)
return a.Principal, a.ExtendErr
}
// Authorize will grant privileges to a Principal
func (a *Authenticator) Authorize(ctx context.Context, w http.ResponseWriter, p oauth2.Principal) error {
cookie := http.Cookie{}
http.SetCookie(w, &cookie)
return nil
}
// Expire revokes privileges from a Principal
func (a *Authenticator) Expire(http.ResponseWriter) {}
// ValidAuthorization returns the Principal
func (a *Authenticator) ValidAuthorization(ctx context.Context, serializedAuthorization string) (oauth2.Principal, error) {
return oauth2.Principal{}, nil
}
// Serialize the serialized values stored on the Authenticator
func (a *Authenticator) Serialize(context.Context, oauth2.Principal) (string, error) {
return a.Serialized, nil
}