@@ -11,73 +11,64 @@ import (
1111 "golang.org/x/oauth2/endpoints"
1212)
1313
14- func NewProviders (config types.OAuthConfig ) * Providers {
15- return & Providers {
16- Config : config ,
17- }
18- }
19-
2014type Providers struct {
2115 Config types.OAuthConfig
2216 Github * oauth.OAuth
2317 Google * oauth.OAuth
2418 Generic * oauth.OAuth
2519}
2620
27- func (providers * Providers ) Init () {
21+ func NewProviders (config types.OAuthConfig ) * Providers {
22+ providers := & Providers {
23+ Config : config ,
24+ }
25+
2826 // If we have a client id and secret for github, initialize the oauth provider
29- if providers . Config . GithubClientId != "" && providers . Config .GithubClientSecret != "" {
27+ if config . GithubClientId != "" && config .GithubClientSecret != "" {
3028 log .Info ().Msg ("Initializing Github OAuth" )
3129
3230 // Create a new oauth provider with the github config
3331 providers .Github = oauth .NewOAuth (oauth2.Config {
34- ClientID : providers . Config .GithubClientId ,
35- ClientSecret : providers . Config .GithubClientSecret ,
36- RedirectURL : fmt .Sprintf ("%s/api/oauth/callback/github" , providers . Config .AppURL ),
32+ ClientID : config .GithubClientId ,
33+ ClientSecret : config .GithubClientSecret ,
34+ RedirectURL : fmt .Sprintf ("%s/api/oauth/callback/github" , config .AppURL ),
3735 Scopes : GithubScopes (),
3836 Endpoint : endpoints .GitHub ,
3937 }, false )
40-
41- // Initialize the oauth provider
42- providers .Github .Init ()
4338 }
4439
4540 // If we have a client id and secret for google, initialize the oauth provider
46- if providers . Config . GoogleClientId != "" && providers . Config .GoogleClientSecret != "" {
41+ if config . GoogleClientId != "" && config .GoogleClientSecret != "" {
4742 log .Info ().Msg ("Initializing Google OAuth" )
4843
4944 // Create a new oauth provider with the google config
5045 providers .Google = oauth .NewOAuth (oauth2.Config {
51- ClientID : providers . Config .GoogleClientId ,
52- ClientSecret : providers . Config .GoogleClientSecret ,
53- RedirectURL : fmt .Sprintf ("%s/api/oauth/callback/google" , providers . Config .AppURL ),
46+ ClientID : config .GoogleClientId ,
47+ ClientSecret : config .GoogleClientSecret ,
48+ RedirectURL : fmt .Sprintf ("%s/api/oauth/callback/google" , config .AppURL ),
5449 Scopes : GoogleScopes (),
5550 Endpoint : endpoints .Google ,
5651 }, false )
57-
58- // Initialize the oauth provider
59- providers .Google .Init ()
6052 }
6153
6254 // If we have a client id and secret for generic oauth, initialize the oauth provider
63- if providers . Config . GenericClientId != "" && providers . Config .GenericClientSecret != "" {
55+ if config . GenericClientId != "" && config .GenericClientSecret != "" {
6456 log .Info ().Msg ("Initializing Generic OAuth" )
6557
6658 // Create a new oauth provider with the generic config
6759 providers .Generic = oauth .NewOAuth (oauth2.Config {
68- ClientID : providers . Config .GenericClientId ,
69- ClientSecret : providers . Config .GenericClientSecret ,
70- RedirectURL : fmt .Sprintf ("%s/api/oauth/callback/generic" , providers . Config .AppURL ),
71- Scopes : providers . Config .GenericScopes ,
60+ ClientID : config .GenericClientId ,
61+ ClientSecret : config .GenericClientSecret ,
62+ RedirectURL : fmt .Sprintf ("%s/api/oauth/callback/generic" , config .AppURL ),
63+ Scopes : config .GenericScopes ,
7264 Endpoint : oauth2.Endpoint {
73- AuthURL : providers . Config .GenericAuthURL ,
74- TokenURL : providers . Config .GenericTokenURL ,
65+ AuthURL : config .GenericAuthURL ,
66+ TokenURL : config .GenericTokenURL ,
7567 },
76- }, providers .Config .GenericSkipSSL )
77-
78- // Initialize the oauth provider
79- providers .Generic .Init ()
68+ }, config .GenericSkipSSL )
8069 }
70+
71+ return providers
8172}
8273
8374func (providers * Providers ) GetProvider (provider string ) * oauth.OAuth {
0 commit comments