oauth2_redirect.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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
  5. import (
  6. "net/http"
  7. "github.com/miniflux/miniflux/http/context"
  8. "github.com/miniflux/miniflux/http/request"
  9. "github.com/miniflux/miniflux/http/response"
  10. "github.com/miniflux/miniflux/http/route"
  11. "github.com/miniflux/miniflux/logger"
  12. "github.com/miniflux/miniflux/ui/session"
  13. )
  14. // OAuth2Redirect redirects the user to the consent page to ask for permission.
  15. func (c *Controller) OAuth2Redirect(w http.ResponseWriter, r *http.Request) {
  16. ctx := context.New(r)
  17. sess := session.New(c.store, ctx)
  18. provider := request.Param(r, "provider", "")
  19. if provider == "" {
  20. logger.Error("[OAuth2] Invalid or missing provider: %s", provider)
  21. response.Redirect(w, r, route.Path(c.router, "login"))
  22. return
  23. }
  24. authProvider, err := getOAuth2Manager(c.cfg).Provider(provider)
  25. if err != nil {
  26. logger.Error("[OAuth2] %v", err)
  27. response.Redirect(w, r, route.Path(c.router, "login"))
  28. return
  29. }
  30. response.Redirect(w, r, authProvider.GetRedirectURL(sess.NewOAuth2State()))
  31. }