|
@@ -50,16 +50,18 @@ func initOIDC(redirectURL string, clientID string, clientSecret string, issuer s
|
|
}
|
|
}
|
|
|
|
|
|
func handleOIDCLogin(w http.ResponseWriter, r *http.Request) {
|
|
func handleOIDCLogin(w http.ResponseWriter, r *http.Request) {
|
|
|
|
+ fmt.Println("# Heree-----> 1")
|
|
var oauth_state_string = logic.RandomString(user_signin_length)
|
|
var oauth_state_string = logic.RandomString(user_signin_length)
|
|
if auth_provider == nil {
|
|
if auth_provider == nil {
|
|
handleOauthNotConfigured(w)
|
|
handleOauthNotConfigured(w)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ fmt.Println("# Heree-----> 2")
|
|
if err := logic.SetState(oauth_state_string); err != nil {
|
|
if err := logic.SetState(oauth_state_string); err != nil {
|
|
handleOauthNotConfigured(w)
|
|
handleOauthNotConfigured(w)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
+ fmt.Println("# Heree-----> 3")
|
|
var url = auth_provider.AuthCodeURL(oauth_state_string)
|
|
var url = auth_provider.AuthCodeURL(oauth_state_string)
|
|
http.Redirect(w, r, url, http.StatusTemporaryRedirect)
|
|
http.Redirect(w, r, url, http.StatusTemporaryRedirect)
|
|
}
|
|
}
|
|
@@ -67,22 +69,25 @@ func handleOIDCLogin(w http.ResponseWriter, r *http.Request) {
|
|
func handleOIDCCallback(w http.ResponseWriter, r *http.Request) {
|
|
func handleOIDCCallback(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
var rState, rCode = getStateAndCode(r)
|
|
var rState, rCode = getStateAndCode(r)
|
|
-
|
|
|
|
|
|
+ fmt.Println("# Heree-----> 4")
|
|
var content, err = getOIDCUserInfo(rState, rCode)
|
|
var content, err = getOIDCUserInfo(rState, rCode)
|
|
if err != nil {
|
|
if err != nil {
|
|
logger.Log(1, "error when getting user info from callback:", err.Error())
|
|
logger.Log(1, "error when getting user info from callback:", err.Error())
|
|
handleOauthNotConfigured(w)
|
|
handleOauthNotConfigured(w)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
+ fmt.Println("# Heree-----> 5")
|
|
if !isEmailAllowed(content.Email) {
|
|
if !isEmailAllowed(content.Email) {
|
|
handleOauthUserNotAllowedToSignUp(w)
|
|
handleOauthUserNotAllowedToSignUp(w)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
+ fmt.Println("# Heree-----> 6")
|
|
// check if user approval is already pending
|
|
// check if user approval is already pending
|
|
if logic.IsPendingUser(content.Email) {
|
|
if logic.IsPendingUser(content.Email) {
|
|
handleOauthUserSignUpApprovalPending(w)
|
|
handleOauthUserSignUpApprovalPending(w)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
+ fmt.Println("# Heree-----> 7")
|
|
_, err = logic.GetUser(content.Email)
|
|
_, err = logic.GetUser(content.Email)
|
|
if err != nil {
|
|
if err != nil {
|
|
if database.IsEmptyRecord(err) { // user must not exist, so try to make one
|
|
if database.IsEmptyRecord(err) { // user must not exist, so try to make one
|
|
@@ -100,6 +105,7 @@ func handleOIDCCallback(w http.ResponseWriter, r *http.Request) {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ fmt.Println("# Heree-----> 8")
|
|
user, err := logic.GetUser(content.Email)
|
|
user, err := logic.GetUser(content.Email)
|
|
if err != nil {
|
|
if err != nil {
|
|
handleOauthUserNotFound(w)
|
|
handleOauthUserNotFound(w)
|
|
@@ -146,7 +152,7 @@ func getOIDCUserInfo(state string, code string) (u *OAuthUser, e error) {
|
|
ctx, cancel := context.WithTimeout(context.Background(), OIDC_TIMEOUT)
|
|
ctx, cancel := context.WithTimeout(context.Background(), OIDC_TIMEOUT)
|
|
defer cancel()
|
|
defer cancel()
|
|
|
|
|
|
- oauth2Token, err := auth_provider.Exchange(ctx, code)
|
|
|
|
|
|
+ oauth2Token, err := auth_provider.Exchange(ctx, code, oauth2.SetAuthURLParam("prompt", "login"))
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to exchange oauth2 token using code \"%s\"", code)
|
|
return nil, fmt.Errorf("failed to exchange oauth2 token using code \"%s\"", code)
|
|
}
|
|
}
|