feature (oauth): redirection link for oauth

This commit is contained in:
Mickael Kerjean 2021-10-13 22:54:15 +11:00
parent 8d413214e2
commit e13262dd36
2 changed files with 6 additions and 1 deletions

View file

@ -6,6 +6,7 @@ import (
. "github.com/mickael-kerjean/filestash/server/common"
"github.com/mickael-kerjean/filestash/server/model"
"net/http"
"strings"
"time"
)
@ -142,5 +143,9 @@ 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)
return
}
SendSuccessResult(res, obj.OAuthURL())
}

View file

@ -32,7 +32,7 @@ func Init(a *App) {
session.HandleFunc("", NewMiddlewareChain(SessionAuthenticate, middlewares, *a)).Methods("POST")
middlewares = []Middleware{ApiHeaders, SecureHeaders, SecureAjax, SessionTry}
session.HandleFunc("", NewMiddlewareChain(SessionLogout, middlewares, *a)).Methods("DELETE")
middlewares = []Middleware{ApiHeaders, SecureHeaders, SecureAjax}
middlewares = []Middleware{ApiHeaders, SecureHeaders}
session.HandleFunc("/auth/{service}", NewMiddlewareChain(SessionOAuthBackend, middlewares, *a)).Methods("GET")
// API for admin