oauth2_redirect.go 978 B

1234567891011121314151617181920212223242526272829303132333435
  1. // Copyright 2017 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package ui // import "miniflux.app/ui"
  5. import (
  6. "net/http"
  7. "miniflux.app/http/request"
  8. "miniflux.app/http/response/html"
  9. "miniflux.app/http/route"
  10. "miniflux.app/logger"
  11. "miniflux.app/ui/session"
  12. )
  13. func (h *handler) oauth2Redirect(w http.ResponseWriter, r *http.Request) {
  14. sess := session.New(h.store, request.SessionID(r))
  15. provider := request.RouteStringParam(r, "provider")
  16. if provider == "" {
  17. logger.Error("[OAuth2] Invalid or missing provider: %s", provider)
  18. html.Redirect(w, r, route.Path(h.router, "login"))
  19. return
  20. }
  21. authProvider, err := getOAuth2Manager(r.Context()).FindProvider(provider)
  22. if err != nil {
  23. logger.Error("[OAuth2] %v", err)
  24. html.Redirect(w, r, route.Path(h.router, "login"))
  25. return
  26. }
  27. html.Redirect(w, r, authProvider.GetRedirectURL(sess.NewOAuth2State()))
  28. }