2021-07-17 16:29:50 +00:00
|
|
|
package oauth
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/yauthdev/yauth/server/constants"
|
|
|
|
"golang.org/x/oauth2"
|
|
|
|
githubOAuth2 "golang.org/x/oauth2/github"
|
|
|
|
googleOAuth2 "golang.org/x/oauth2/google"
|
|
|
|
)
|
|
|
|
|
|
|
|
type OAuthProviders struct {
|
2021-07-17 23:18:42 +00:00
|
|
|
GoogleConfig *oauth2.Config
|
|
|
|
GithubConfig *oauth2.Config
|
|
|
|
// FacebookConfig *oauth2.Config
|
2021-07-17 16:29:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var OAuthProvider OAuthProviders
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
if constants.GOOGLE_CLIENT_ID != "" && constants.GOOGLE_CLIENT_SECRET != "" {
|
|
|
|
OAuthProvider.GoogleConfig = &oauth2.Config{
|
|
|
|
ClientID: constants.GOOGLE_CLIENT_ID,
|
|
|
|
ClientSecret: constants.GOOGLE_CLIENT_SECRET,
|
|
|
|
RedirectURL: constants.SERVER_URL + "/callback/google",
|
|
|
|
Endpoint: googleOAuth2.Endpoint,
|
|
|
|
Scopes: []string{"https://www.googleapis.com/auth/userinfo.email", "https://www.googleapis.com/auth/userinfo.profile"},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if constants.GITHUB_CLIENT_ID != "" && constants.GITHUB_CLIENT_SECRET != "" {
|
2021-07-17 23:18:42 +00:00
|
|
|
OAuthProvider.GithubConfig = &oauth2.Config{
|
2021-07-17 16:29:50 +00:00
|
|
|
ClientID: constants.GITHUB_CLIENT_ID,
|
|
|
|
ClientSecret: constants.GITHUB_CLIENT_SECRET,
|
|
|
|
RedirectURL: constants.SERVER_URL + "/callback/github",
|
|
|
|
Endpoint: githubOAuth2.Endpoint,
|
|
|
|
}
|
|
|
|
}
|
2021-07-17 23:18:42 +00:00
|
|
|
// if constants.FACEBOOK_CLIENT_ID != "" && constants.FACEBOOK_CLIENT_SECRET != "" {
|
|
|
|
// OAuthProvider.FacebookConfig = &oauth2.Config{
|
|
|
|
// ClientID: constants.FACEBOOK_CLIENT_ID,
|
|
|
|
// ClientSecret: constants.FACEBOOK_CLIENT_SECRET,
|
|
|
|
// RedirectURL: constants.SERVER_URL + "/callback/facebook/",
|
|
|
|
// Endpoint: facebookOAuth2.Endpoint,
|
|
|
|
// }
|
|
|
|
// }
|
2021-07-17 16:29:50 +00:00
|
|
|
}
|