mirror of
https://github.com/portainer/portainer.git
synced 2025-07-23 15:29:42 +02:00
feat(oauth): add support for default team
This commit is contained in:
parent
78e2aaf7d4
commit
d768e72a21
1 changed files with 13 additions and 1 deletions
|
@ -34,7 +34,7 @@ func (handler *Handler) validateOAuth(w http.ResponseWriter, r *http.Request) *h
|
||||||
}
|
}
|
||||||
|
|
||||||
if settings.AuthenticationMethod != 3 {
|
if settings.AuthenticationMethod != 3 {
|
||||||
return &httperror.HandlerError{http.StatusForbidden, "OAuth authentication is not being used", err}
|
return &httperror.HandlerError{http.StatusForbidden, "OAuth authentication is not enabled", err}
|
||||||
}
|
}
|
||||||
|
|
||||||
token, err := handler.OAuthService.GetAccessToken(payload.Code, &settings.OAuthSettings)
|
token, err := handler.OAuthService.GetAccessToken(payload.Code, &settings.OAuthSettings)
|
||||||
|
@ -69,6 +69,18 @@ func (handler *Handler) validateOAuth(w http.ResponseWriter, r *http.Request) *h
|
||||||
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist user inside the database", err}
|
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist user inside the database", err}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if settings.OAuthSettings.DefaultTeamID != 0 {
|
||||||
|
membership := &portainer.TeamMembership{
|
||||||
|
UserID: user.ID,
|
||||||
|
TeamID: settings.OAuthSettings.DefaultTeamID,
|
||||||
|
Role: portainer.TeamMember,
|
||||||
|
}
|
||||||
|
|
||||||
|
err = handler.TeamMembershipService.CreateTeamMembership(membership)
|
||||||
|
if err != nil {
|
||||||
|
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist team membership inside the database", err}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return handler.writeToken(w, user)
|
return handler.writeToken(w, user)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue