forked from getfider/fider
-
Notifications
You must be signed in to change notification settings - Fork 0
/
oauth.go
46 lines (40 loc) · 1.42 KB
/
oauth.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
package oauth
import (
"errors"
)
const (
//FacebookProvider is const for 'facebook'
FacebookProvider = "facebook"
//GoogleProvider is const for 'google'
GoogleProvider = "google"
//GitHubProvider is const for 'github'
GitHubProvider = "github"
)
//ErrUserIDRequired is used when OAuth integration returns an empty user ID
var ErrUserIDRequired = errors.New("UserID is required during OAuth integration")
//UserProfile represents an OAuth user profile
type UserProfile struct {
ID string `json:"id"`
Name string `json:"name"`
Email string `json:"email"`
}
//ProviderOption represents an OAuth provider that can be used to authenticate
type ProviderOption struct {
Provider string `json:"provider"`
DisplayName string `json:"displayName"`
ClientID string `json:"clientID"`
URL string `json:"url"`
CallbackURL string `json:"callbackURL"`
LogoBlobKey string `json:"logoBlobKey"`
IsCustomProvider bool `json:"isCustomProvider"`
IsEnabled bool `json:"isEnabled"`
}
//Service provides OAuth operations
type Service interface {
GetAuthURL(provider, redirect, identifier string) (string, error)
GetProfile(provider string, code string) (*UserProfile, error)
GetRawProfile(provider string, code string) (string, error)
ParseRawProfile(provider, body string) (*UserProfile, error)
ListActiveProviders() ([]*ProviderOption, error)
ListAllProviders() ([]*ProviderOption, error)
}