forked from getfider/fider
-
Notifications
You must be signed in to change notification settings - Fork 0
/
oauth.go
68 lines (56 loc) · 1.9 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package mock
import "github.com/getfider/fider/app/pkg/oauth"
//OAuthService implements a mocked OAuthService
type OAuthService struct{}
//GetAuthURL returns authentication url for given provider
func (s *OAuthService) GetAuthURL(provider, redirect, identifier string) (string, error) {
return "http://avengers.test.fider.io/oauth/token?provider=" + provider + "&redirect=" + redirect + "|" + identifier, nil
}
//GetRawProfile returns raw JSON response from Profile API
func (s *OAuthService) GetRawProfile(provider string, code string) (string, error) {
return "", nil
}
//ParseRawProfile parses raw profile response into UserProfile model
func (s *OAuthService) ParseRawProfile(provider, body string) (*oauth.UserProfile, error) {
return nil, nil
}
//GetProfile returns user profile based on provider and code
func (s *OAuthService) GetProfile(provider string, code string) (*oauth.UserProfile, error) {
if provider == "facebook" && code == "123" {
return &oauth.UserProfile{
ID: "FB123",
Name: "Jon Snow",
Email: "jon.snow@got.com",
}, nil
}
if provider == "facebook" && code == "456" {
return &oauth.UserProfile{
ID: "FB456",
Name: "Some Facebook Guy",
Email: "some.guy@facebook.com",
}, nil
}
if provider == "facebook" && code == "798" {
return &oauth.UserProfile{
ID: "FB798",
Name: "Mark",
Email: "",
}, nil
}
if provider == "google" && code == "123" {
return &oauth.UserProfile{
ID: "GO123",
Name: "Jon Snow",
Email: "jon.snow@got.com",
}, nil
}
return nil, nil
}
//ListActiveProviders returns a list of all providers for current tenant
func (s *OAuthService) ListActiveProviders() ([]*oauth.ProviderOption, error) {
return []*oauth.ProviderOption{}, nil
}
//ListAllProviders returns a list of all providers for current tenant
func (s *OAuthService) ListAllProviders() ([]*oauth.ProviderOption, error) {
return []*oauth.ProviderOption{}, nil
}