2023-06-19 17:42:47 -04:00
|
|
|
// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
2018-04-29 19:35:04 -04:00
|
|
|
|
2018-10-07 21:42:43 -04:00
|
|
|
package ui // import "miniflux.app/ui"
|
2018-04-29 19:35:04 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2018-08-25 00:51:50 -04:00
|
|
|
"miniflux.app/http/request"
|
2018-10-07 21:42:43 -04:00
|
|
|
"miniflux.app/http/response/html"
|
2018-08-25 00:51:50 -04:00
|
|
|
"miniflux.app/http/route"
|
|
|
|
"miniflux.app/logger"
|
|
|
|
"miniflux.app/ui/session"
|
2018-04-29 19:35:04 -04:00
|
|
|
)
|
|
|
|
|
2018-11-11 14:28:29 -05:00
|
|
|
func (h *handler) oauth2Redirect(w http.ResponseWriter, r *http.Request) {
|
|
|
|
sess := session.New(h.store, request.SessionID(r))
|
2018-04-29 19:35:04 -04:00
|
|
|
|
2018-09-24 00:02:26 -04:00
|
|
|
provider := request.RouteStringParam(r, "provider")
|
2018-04-29 19:35:04 -04:00
|
|
|
if provider == "" {
|
|
|
|
logger.Error("[OAuth2] Invalid or missing provider: %s", provider)
|
2018-11-11 14:28:29 -05:00
|
|
|
html.Redirect(w, r, route.Path(h.router, "login"))
|
2018-04-29 19:35:04 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-12-22 00:14:10 -05:00
|
|
|
authProvider, err := getOAuth2Manager(r.Context()).FindProvider(provider)
|
2018-04-29 19:35:04 -04:00
|
|
|
if err != nil {
|
|
|
|
logger.Error("[OAuth2] %v", err)
|
2018-11-11 14:28:29 -05:00
|
|
|
html.Redirect(w, r, route.Path(h.router, "login"))
|
2018-04-29 19:35:04 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-10-07 21:42:43 -04:00
|
|
|
html.Redirect(w, r, authProvider.GetRedirectURL(sess.NewOAuth2State()))
|
2018-04-29 19:35:04 -04:00
|
|
|
}
|