aboutsummaryrefslogtreecommitdiff
path: root/server/auth/provider.go
blob: ae512bd715fc0f7523093279873719e14a8640f2 (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
package auth

import "golang.org/x/oauth2"

type Provider interface {
	Name() string
	StartSession(string) *Session
	Exchange(string) (*oauth2.Token, error)
	Username(*oauth2.Token) string
	Valid(*oauth2.Token) bool
	Revoke(*oauth2.Token) error
}

type Session struct {
	AuthURL string
	Token   *oauth2.Token
	State   string
}

func (s *Session) Authorize(provider Provider, code string) error {
	t, err := provider.Exchange(code)
	if err != nil {
		return err
	}
	s.Token = t
	return nil
}