Add github login

Resolves #18
This commit is contained in:
Lakhan Samani
2021-07-18 04:48:42 +05:30
parent 245a5b5e1b
commit 7b16213e22
5 changed files with 149 additions and 66 deletions

View File

@@ -3,15 +3,14 @@ package oauth
import (
"github.com/yauthdev/yauth/server/constants"
"golang.org/x/oauth2"
facebookOAuth2 "golang.org/x/oauth2/facebook"
githubOAuth2 "golang.org/x/oauth2/github"
googleOAuth2 "golang.org/x/oauth2/google"
)
type OAuthProviders struct {
GoogleConfig *oauth2.Config
GithubConfig *oauth2.Config
FacebookConfig *oauth2.Config
GoogleConfig *oauth2.Config
GithubConfig *oauth2.Config
// FacebookConfig *oauth2.Config
}
var OAuthProvider OAuthProviders
@@ -27,19 +26,19 @@ func init() {
}
}
if constants.GITHUB_CLIENT_ID != "" && constants.GITHUB_CLIENT_SECRET != "" {
OAuthProvider.GoogleConfig = &oauth2.Config{
OAuthProvider.GithubConfig = &oauth2.Config{
ClientID: constants.GITHUB_CLIENT_ID,
ClientSecret: constants.GITHUB_CLIENT_SECRET,
RedirectURL: constants.SERVER_URL + "/callback/github",
Endpoint: githubOAuth2.Endpoint,
}
}
if constants.FACEBOOK_CLIENT_ID != "" && constants.FACEBOOK_CLIENT_SECRET != "" {
OAuthProvider.GoogleConfig = &oauth2.Config{
ClientID: constants.FACEBOOK_CLIENT_ID,
ClientSecret: constants.FACEBOOK_CLIENT_SECRET,
RedirectURL: constants.SERVER_URL + "/callback/facebook/",
Endpoint: facebookOAuth2.Endpoint,
}
}
// 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,
// }
// }
}