Skip to content

Commit

Permalink
dev: Fix callback parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
adriansmares committed Nov 26, 2021
1 parent f66dd05 commit 56db800
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions pkg/web/oauthclient/callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ package oauthclient

import (
"context"
"encoding/json"
stderrors "errors"
"net/http"

"github.com/gorilla/schema"
"go.thethings.network/lorawan-stack/v3/pkg/errors"
"go.thethings.network/lorawan-stack/v3/pkg/webhandlers"
"golang.org/x/oauth2"
Expand All @@ -35,10 +35,10 @@ var (
)

type oauthAuthorizeResponse struct {
Error string `form:"error" query:"error"`
ErrorDescription string `form:"error_description" query:"error_description"`
State string `form:"state" query:"state"`
Code string `form:"code" query:"code"`
Error string `schema:"error"`
ErrorDescription string `schema:"error_description"`
State string `schema:"state"`
Code string `schema:"code"`
}

func (res *oauthAuthorizeResponse) ValidateContext(c context.Context) error {
Expand All @@ -58,8 +58,11 @@ func (res *oauthAuthorizeResponse) ValidateContext(c context.Context) error {
// access token.
func (oc *OAuthClient) HandleCallback(w http.ResponseWriter, r *http.Request) {
var response oauthAuthorizeResponse
err := json.NewDecoder(r.Body).Decode(&response)
if err != nil {
if err := r.ParseForm(); err != nil {
webhandlers.Error(w, r, err)
return
}
if err := schema.NewDecoder().Decode(&response, r.Form); err != nil {
webhandlers.Error(w, r, err)
return
}
Expand All @@ -77,6 +80,7 @@ func (oc *OAuthClient) HandleCallback(w http.ResponseWriter, r *http.Request) {
// redirect back to the client mount instead of showing an error.
if acErr != nil {
webhandlers.Error(w, r, acErr)
return
}
if value.AccessToken != "" {
config := oc.configFromContext(r.Context())
Expand Down

0 comments on commit 56db800

Please sign in to comment.