mirror of
https://github.com/zitadel/zitadel.git
synced 2025-02-28 23:57:23 +00:00
fix: nil pointer in external providers (#2642)
* fix: nil pointer in external providers * fix returns
This commit is contained in:
parent
af1f10b7ca
commit
685ffc5dc7
@ -89,7 +89,11 @@ func (l *Login) handleIDP(w http.ResponseWriter, r *http.Request, authReq *domai
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (l *Login) handleOIDCAuthorize(w http.ResponseWriter, r *http.Request, authReq *domain.AuthRequest, idpConfig *iam_model.IDPConfigView, callbackEndpoint string) {
|
func (l *Login) handleOIDCAuthorize(w http.ResponseWriter, r *http.Request, authReq *domain.AuthRequest, idpConfig *iam_model.IDPConfigView, callbackEndpoint string) {
|
||||||
provider := l.getRPConfig(w, r, authReq, idpConfig, callbackEndpoint)
|
provider, err := l.getRPConfig(idpConfig, callbackEndpoint)
|
||||||
|
if err != nil {
|
||||||
|
l.renderLogin(w, r, authReq, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
http.Redirect(w, r, rp.AuthURL(authReq.ID, provider, rp.WithPrompt(oidc.PromptSelectAccount)), http.StatusFound)
|
http.Redirect(w, r, rp.AuthURL(authReq.ID, provider, rp.WithPrompt(oidc.PromptSelectAccount)), http.StatusFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,7 +139,11 @@ func (l *Login) handleExternalLoginCallback(w http.ResponseWriter, r *http.Reque
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if idpConfig.IsOIDC {
|
if idpConfig.IsOIDC {
|
||||||
provider := l.getRPConfig(w, r, authReq, idpConfig, EndpointExternalLoginCallback)
|
provider, err := l.getRPConfig(idpConfig, EndpointExternalLoginCallback)
|
||||||
|
if err != nil {
|
||||||
|
l.renderLogin(w, r, authReq, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
tokens, err := rp.CodeExchange(r.Context(), data.Code, provider)
|
tokens, err := rp.CodeExchange(r.Context(), data.Code, provider)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.renderLogin(w, r, authReq, err)
|
l.renderLogin(w, r, authReq, err)
|
||||||
@ -145,26 +153,18 @@ func (l *Login) handleExternalLoginCallback(w http.ResponseWriter, r *http.Reque
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
l.renderError(w, r, authReq, caos_errors.ThrowPreconditionFailed(nil, "RP-asff2", "Errors.ExternalIDP.IDPTypeNotImplemented"))
|
l.renderError(w, r, authReq, caos_errors.ThrowPreconditionFailed(nil, "RP-asff2", "Errors.ExternalIDP.IDPTypeNotImplemented"))
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *Login) getRPConfig(w http.ResponseWriter, r *http.Request, authReq *domain.AuthRequest, idpConfig *iam_model.IDPConfigView, callbackEndpoint string) rp.RelyingParty {
|
func (l *Login) getRPConfig(idpConfig *iam_model.IDPConfigView, callbackEndpoint string) (rp.RelyingParty, error) {
|
||||||
oidcClientSecret, err := crypto.DecryptString(idpConfig.OIDCClientSecret, l.IDPConfigAesCrypto)
|
oidcClientSecret, err := crypto.DecryptString(idpConfig.OIDCClientSecret, l.IDPConfigAesCrypto)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.renderError(w, r, authReq, err)
|
return nil, err
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
if idpConfig.OIDCIssuer != "" {
|
if idpConfig.OIDCIssuer != "" {
|
||||||
provider, err := rp.NewRelyingPartyOIDC(idpConfig.OIDCIssuer, idpConfig.OIDCClientID, oidcClientSecret, l.baseURL+callbackEndpoint, idpConfig.OIDCScopes, rp.WithVerifierOpts(rp.WithIssuedAtOffset(3*time.Second)))
|
return rp.NewRelyingPartyOIDC(idpConfig.OIDCIssuer, idpConfig.OIDCClientID, oidcClientSecret, l.baseURL+callbackEndpoint, idpConfig.OIDCScopes, rp.WithVerifierOpts(rp.WithIssuedAtOffset(3*time.Second)))
|
||||||
if err != nil {
|
|
||||||
l.renderError(w, r, authReq, err)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return provider
|
|
||||||
}
|
}
|
||||||
if idpConfig.OAuthAuthorizationEndpoint == "" || idpConfig.OAuthTokenEndpoint == "" {
|
if idpConfig.OAuthAuthorizationEndpoint == "" || idpConfig.OAuthTokenEndpoint == "" {
|
||||||
l.renderError(w, r, authReq, caos_errors.ThrowPreconditionFailed(nil, "RP-4n0fs", "Errors.IdentityProvider.InvalidConfig"))
|
return nil, caos_errors.ThrowPreconditionFailed(nil, "RP-4n0fs", "Errors.IdentityProvider.InvalidConfig")
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
oauth2Config := &oauth2.Config{
|
oauth2Config := &oauth2.Config{
|
||||||
ClientID: idpConfig.OIDCClientID,
|
ClientID: idpConfig.OIDCClientID,
|
||||||
@ -176,12 +176,7 @@ func (l *Login) getRPConfig(w http.ResponseWriter, r *http.Request, authReq *dom
|
|||||||
RedirectURL: l.baseURL + callbackEndpoint,
|
RedirectURL: l.baseURL + callbackEndpoint,
|
||||||
Scopes: idpConfig.OIDCScopes,
|
Scopes: idpConfig.OIDCScopes,
|
||||||
}
|
}
|
||||||
provider, err := rp.NewRelyingPartyOAuth(oauth2Config, rp.WithVerifierOpts(rp.WithIssuedAtOffset(3*time.Second)))
|
return rp.NewRelyingPartyOAuth(oauth2Config, rp.WithVerifierOpts(rp.WithIssuedAtOffset(3*time.Second)))
|
||||||
if err != nil {
|
|
||||||
l.renderError(w, r, authReq, err)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return provider
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *Login) handleExternalUserAuthenticated(w http.ResponseWriter, r *http.Request, authReq *domain.AuthRequest, idpConfig *iam_model.IDPConfigView, userAgentID string, tokens *oidc.Tokens) {
|
func (l *Login) handleExternalUserAuthenticated(w http.ResponseWriter, r *http.Request, authReq *domain.AuthRequest, idpConfig *iam_model.IDPConfigView, userAgentID string, tokens *oidc.Tokens) {
|
||||||
|
@ -97,7 +97,11 @@ func (l *Login) handleExternalRegisterCallback(w http.ResponseWriter, r *http.Re
|
|||||||
l.renderError(w, r, authReq, err)
|
l.renderError(w, r, authReq, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
provider := l.getRPConfig(w, r, authReq, idpConfig, EndpointExternalRegisterCallback)
|
provider, err := l.getRPConfig(idpConfig, EndpointExternalRegisterCallback)
|
||||||
|
if err != nil {
|
||||||
|
l.renderRegisterOption(w, r, authReq, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
tokens, err := rp.CodeExchange(r.Context(), data.Code, provider)
|
tokens, err := rp.CodeExchange(r.Context(), data.Code, provider)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.renderRegisterOption(w, r, authReq, err)
|
l.renderRegisterOption(w, r, authReq, err)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user