mirror of
https://github.com/mickael-kerjean/filestash
synced 2025-12-15 21:04:46 +01:00
feature (next): support for next in oauth2 backends
This commit is contained in:
parent
73c2386868
commit
57a60fc838
4 changed files with 29 additions and 8 deletions
|
|
@ -7,8 +7,11 @@ class SessionManager {
|
|||
.then((data) => data.result);
|
||||
}
|
||||
|
||||
oauth2(url) {
|
||||
return http_get(url)
|
||||
oauth2(url, next) {
|
||||
const u = new URL(document.location);
|
||||
u.pathname = url;
|
||||
if (next) u.searchParams.set("next", next);
|
||||
return http_get(u.toString())
|
||||
.then((data) => data.result);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ function ConnectPageComponent({ error, history }) {
|
|||
return;
|
||||
} else if ("oauth2" in formData) {
|
||||
setIsLoading(true);
|
||||
Session.oauth2(formData["oauth2"]).then((url) => {
|
||||
Session.oauth2(formData["oauth2"], _GET["next"]).then((url) => {
|
||||
window.location.href = url;
|
||||
}).catch((err) => error(err));
|
||||
return;
|
||||
|
|
@ -60,7 +60,12 @@ function ConnectPageComponent({ error, history }) {
|
|||
|
||||
useEffect(() => {
|
||||
if (_GET["state"]) { // oauth2/oidc
|
||||
authenticate({ ..._GET, type: _GET["state"] }).catch((err) => error(err));
|
||||
const [type, next] = _GET["state"].split("::")
|
||||
authenticate({
|
||||
..._GET,
|
||||
next: next,
|
||||
type: type,
|
||||
}).catch((err) => error(err));
|
||||
} else if (_GET["type"]) { // form using get
|
||||
authenticate(_GET).catch((err) => error(err));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import (
|
|||
. "github.com/mickael-kerjean/filestash/server/middleware"
|
||||
"github.com/mickael-kerjean/filestash/server/model"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
|
@ -153,11 +154,24 @@ func SessionOAuthBackend(ctx App, res http.ResponseWriter, req *http.Request) {
|
|||
SendErrorResult(res, ErrNotSupported)
|
||||
return
|
||||
}
|
||||
if strings.Contains(req.Header.Get("Accept"), "text/html") {
|
||||
http.Redirect(res, req, obj.OAuthURL(), http.StatusSeeOther)
|
||||
redirectUrl, err := url.Parse(obj.OAuthURL())
|
||||
if err != nil {
|
||||
Log.Debug("session::oauth 'Parse URL - \"%s\"'", a["type"])
|
||||
SendErrorResult(res, ErrNotValid)
|
||||
return
|
||||
}
|
||||
SendSuccessResult(res, obj.OAuthURL())
|
||||
stateValue := vars["service"]
|
||||
if req.URL.Query().Get("next") != "" {
|
||||
stateValue += "::" + req.URL.Query().Get("next")
|
||||
}
|
||||
q := redirectUrl.Query()
|
||||
q.Set("state", stateValue)
|
||||
redirectUrl.RawQuery = q.Encode()
|
||||
if strings.Contains(req.Header.Get("Accept"), "text/html") {
|
||||
http.Redirect(res, req, redirectUrl.String(), http.StatusSeeOther)
|
||||
return
|
||||
}
|
||||
SendSuccessResult(res, redirectUrl.String())
|
||||
}
|
||||
|
||||
func SessionAuthMiddleware(ctx App, res http.ResponseWriter, req *http.Request) {
|
||||
|
|
|
|||
|
|
@ -70,7 +70,6 @@ func (d Dropbox) OAuthURL() string {
|
|||
url += "client_id=" + d.ClientId
|
||||
url += "&redirect_uri=https://" + d.Hostname + "/login"
|
||||
url += "&response_type=token"
|
||||
url += "&state=dropbox"
|
||||
return url
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue