kopia lustrzana https://codeberg.org/nmkj/audon
fix oauth redirect_uri
rodzic
32dbfbc205
commit
80963c96e6
19
auth.go
19
auth.go
|
@ -66,7 +66,7 @@ func loginHandler(c echo.Context) (err error) {
|
||||||
req.Redirect = "/"
|
req.Redirect = "/"
|
||||||
}
|
}
|
||||||
|
|
||||||
appConfig, err := getAppConfig(serverURL.String(), req.Redirect)
|
appConfig, err := getAppConfig(serverURL.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ErrInvalidRequestFormat
|
return ErrInvalidRequestFormat
|
||||||
}
|
}
|
||||||
|
@ -89,6 +89,15 @@ func loginHandler(c echo.Context) (err error) {
|
||||||
return echo.NewHTTPError(http.StatusInternalServerError)
|
return echo.NewHTTPError(http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
redirURL, err := url.Parse(mastApp.AuthURI)
|
||||||
|
if err != nil {
|
||||||
|
c.Logger().Warn(err)
|
||||||
|
return echo.NewHTTPError(http.StatusInternalServerError, "invalid_auth_uri")
|
||||||
|
}
|
||||||
|
q := redirURL.Query()
|
||||||
|
q.Add("state", req.Redirect)
|
||||||
|
redirURL.RawQuery = q.Encode()
|
||||||
|
|
||||||
return c.String(http.StatusCreated, mastApp.AuthURI)
|
return c.String(http.StatusCreated, mastApp.AuthURI)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,8 +105,8 @@ func loginHandler(c echo.Context) (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
type OAuthRequest struct {
|
type OAuthRequest struct {
|
||||||
Code string `query:"code"`
|
Code string `query:"code"`
|
||||||
Redirect string `query:"redir"`
|
State string `query:"state"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// handler for GET to /app/oauth?code=****
|
// handler for GET to /app/oauth?code=****
|
||||||
|
@ -122,7 +131,7 @@ func oauthHandler(c echo.Context) (err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
appConf, err := getAppConfig(data.MastodonConfig.Server, req.Redirect)
|
appConf, err := getAppConfig(data.MastodonConfig.Server)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return echo.NewHTTPError(http.StatusBadRequest, err.Error())
|
return echo.NewHTTPError(http.StatusBadRequest, err.Error())
|
||||||
}
|
}
|
||||||
|
@ -178,7 +187,7 @@ func oauthHandler(c echo.Context) (err error) {
|
||||||
return echo.NewHTTPError(http.StatusInternalServerError)
|
return echo.NewHTTPError(http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.Redirect(http.StatusFound, req.Redirect)
|
return c.Redirect(http.StatusFound, req.State)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getUserTokenHandler(c echo.Context) (err error) {
|
func getUserTokenHandler(c echo.Context) (err error) {
|
||||||
|
|
|
@ -225,19 +225,13 @@ func (cv *CustomValidator) Validate(i interface{}) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getAppConfig(server string, redirPath string) (*mastodon.AppConfig, error) {
|
func getAppConfig(server string) (*mastodon.AppConfig, error) {
|
||||||
if redirPath == "" {
|
|
||||||
redirPath = "/"
|
|
||||||
}
|
|
||||||
redirectURI := "urn:ietf:wg:oauth:2.0:oob"
|
redirectURI := "urn:ietf:wg:oauth:2.0:oob"
|
||||||
u := &url.URL{
|
u := &url.URL{
|
||||||
Host: mainConfig.LocalDomain,
|
Host: mainConfig.LocalDomain,
|
||||||
Scheme: "https",
|
Scheme: "https",
|
||||||
Path: "/",
|
Path: "/",
|
||||||
}
|
}
|
||||||
q := u.Query()
|
|
||||||
q.Add("redir", redirPath)
|
|
||||||
u.RawQuery = q.Encode()
|
|
||||||
u = u.JoinPath("app", "oauth")
|
u = u.JoinPath("app", "oauth")
|
||||||
redirectURI = u.String()
|
redirectURI = u.String()
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue