Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(redis): handle Publish UserInfo #11

Merged
merged 1 commit into from
Jan 18, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions internal/controllers/rest_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ func (rc RESTController) OIDCProviderCallback(w http.ResponseWriter, r *http.Req
// ...publish a new message to be consumed.
if err = rc.oidcService.PublishUserInfo(context.Background(), token); err != nil {
rc.logger.Errorf("An error occurred while publishing: %v", err)
rc.internalServerError(w, err)
return
}

// rc.oidcService.PublishMessage(context.Background(), token.CustomClaims.)
Expand Down Expand Up @@ -189,15 +191,23 @@ func (rc RESTController) deleteSessionCookie(w http.ResponseWriter, name string)
http.SetCookie(w, &http.Cookie{Name: name, MaxAge: -1, Path: rc.configuration.AuthServiceURL})
}

func (rc RESTController) forbiddenResponse(w http.ResponseWriter, err error) {
w.WriteHeader(http.StatusForbidden)
func (rc RESTController) errorResponse(w http.ResponseWriter, code int, err error) {
w.WriteHeader(code)
jsonBody := models.ErrorResponse{
Message: err.Error(),
Timestamp: time.Now(),
}
json.NewEncoder(w).Encode(jsonBody)
}

func (rc RESTController) forbiddenResponse(w http.ResponseWriter, err error) {
rc.errorResponse(w, http.StatusForbidden, err)
}

func (rc RESTController) internalServerError(w http.ResponseWriter, err error) {
rc.errorResponse(w, http.StatusInternalServerError, err)
}

// skipURLsMiddleware is a middleware that skips all requests configured in SKIP_URL.
func (rc RESTController) skipURLsMiddleware() gin.HandlerFunc {
return func(c *gin.Context) {
Expand Down