aboutsummaryrefslogtreecommitdiffhomepage
path: root/ui/oauth2_callback.go
diff options
context:
space:
mode:
authorGravatar Frédéric Guillot <fred@miniflux.net>2018-09-03 14:26:40 -0700
committerGravatar Frédéric Guillot <fred@miniflux.net>2018-09-03 14:26:40 -0700
commiteee1f3190355224eef63a4dcdef8c36eb3ca3738 (patch)
tree009b7ca67b96d9be473d8ddf2c8c95f22a6749d1 /ui/oauth2_callback.go
parent88e81d4d800ff6433518522954197d75203a25c2 (diff)
Refactor HTTP context handling
Diffstat (limited to 'ui/oauth2_callback.go')
-rw-r--r--ui/oauth2_callback.go18
1 files changed, 8 insertions, 10 deletions
diff --git a/ui/oauth2_callback.go b/ui/oauth2_callback.go
index 4e0cd74..b1bb933 100644
--- a/ui/oauth2_callback.go
+++ b/ui/oauth2_callback.go
@@ -7,7 +7,6 @@ package ui // import "miniflux.app/ui"
import (
"net/http"
- "miniflux.app/http/context"
"miniflux.app/http/cookie"
"miniflux.app/http/request"
"miniflux.app/http/response"
@@ -20,8 +19,7 @@ import (
// OAuth2Callback receives the authorization code and create a new session.
func (c *Controller) OAuth2Callback(w http.ResponseWriter, r *http.Request) {
- ctx := context.New(r)
- sess := session.New(c.store, ctx)
+ sess := session.New(c.store, request.SessionID(r))
provider := request.Param(r, "provider", "")
if provider == "" {
@@ -38,8 +36,8 @@ func (c *Controller) OAuth2Callback(w http.ResponseWriter, r *http.Request) {
}
state := request.QueryParam(r, "state", "")
- if state == "" || state != ctx.OAuth2State() {
- logger.Error(`[OAuth2] Invalid state value: got "%s" instead of "%s"`, state, ctx.OAuth2State())
+ if state == "" || state != request.OAuth2State(r) {
+ logger.Error(`[OAuth2] Invalid state value: got "%s" instead of "%s"`, state, request.OAuth2State(r))
response.Redirect(w, r, route.Path(c.router, "login"))
return
}
@@ -58,7 +56,7 @@ func (c *Controller) OAuth2Callback(w http.ResponseWriter, r *http.Request) {
return
}
- if ctx.IsAuthenticated() {
+ if request.IsAuthenticated(r) {
user, err := c.store.UserByExtraField(profile.Key, profile.ID)
if err != nil {
html.ServerError(w, err)
@@ -66,18 +64,18 @@ func (c *Controller) OAuth2Callback(w http.ResponseWriter, r *http.Request) {
}
if user != nil {
- logger.Error("[OAuth2] User #%d cannot be associated because %s is already associated", ctx.UserID(), user.Username)
- sess.NewFlashErrorMessage(c.translator.GetLanguage(ctx.UserLanguage()).Get("There is already someone associated with this provider!"))
+ logger.Error("[OAuth2] User #%d cannot be associated because %s is already associated", request.UserID(r), user.Username)
+ sess.NewFlashErrorMessage(c.translator.GetLanguage(request.UserLanguage(r)).Get("There is already someone associated with this provider!"))
response.Redirect(w, r, route.Path(c.router, "settings"))
return
}
- if err := c.store.UpdateExtraField(ctx.UserID(), profile.Key, profile.ID); err != nil {
+ if err := c.store.UpdateExtraField(request.UserID(r), profile.Key, profile.ID); err != nil {
html.ServerError(w, err)
return
}
- sess.NewFlashMessage(c.translator.GetLanguage(ctx.UserLanguage()).Get("Your external account is now linked!"))
+ sess.NewFlashMessage(c.translator.GetLanguage(request.UserLanguage(r)).Get("Your external account is now linked!"))
response.Redirect(w, r, route.Path(c.router, "settings"))
return
}