~netlandish/gobwebs-oauth2

92718acf16fac98c8a79f63edf97a9685b68487e — Peter Sanchez 1 year, 6 months ago a54d2dc
Fixing json introspect output
1 files changed, 21 insertions(+), 21 deletions(-)

M routes.go
M routes.go => routes.go +21 -21
@@ 87,45 87,45 @@ func (s *Service) Introspect(c echo.Context) error {
	ctype := req.Header.Get("Content-Type")
	if ctype != "application/x-www-form-urlencoded" {
		retErr := struct {
			err  string `json:"error"`
			desc string `json:"error_description"`
			uri  string `json:"error_url"` // TODO Make this customizable
			Err  string `json:"error"`
			Desc string `json:"error_description"`
			URI  string `json:"error_url"` // TODO Make this customizable
		}{
			err:  "invalid request",
			desc: "Content-Type must be application/x-www-form-urlencoded",
			Err:  "invalid request",
			Desc: "Content-Type must be application/x-www-form-urlencoded",
		}
		return c.JSON(http.StatusBadRequest, &retErr)
	}

	retFalse := struct {
		active bool `json:"active"`
		Active bool `json:"active"`
	}{false}

	token := ForContext(req.Context())
	if token == nil {
		return c.JSON(http.StatusOK, retFalse)
		return c.JSON(http.StatusOK, &retFalse)
	}

	if token.Token.ClientID == "" {
		return c.JSON(http.StatusOK, retFalse)
		return c.JSON(http.StatusOK, &retFalse)
	}

	ret := struct {
		active    bool   `json:"active"`
		clientID  string `json:"client_id"`
		username  string `json:"username"`
		tokenType string `json:"token_type"`
		exp       int    `json:"exp"`
		iat       int    `json:"iat"`
		Active    bool   `json:"active"`
		ClientID  string `json:"client_id"`
		Username  string `json:"username"`
		TokenType string `json:"token_type"`
		Exp       int    `json:"exp"`
		Iat       int    `json:"iat"`
	}{
		active:    true,
		clientID:  token.Token.ClientID,
		username:  token.User.GetEmail(),
		tokenType: "bearer",
		exp:       int(token.Token.Expires),
		iat:       int(token.Token.Issued),
		Active:    true,
		ClientID:  token.Token.ClientID,
		Username:  token.User.GetEmail(),
		TokenType: "bearer",
		Exp:       int(token.Token.Expires),
		Iat:       int(token.Token.Issued),
	}
	return c.JSON(http.StatusOK, ret)
	return c.JSON(http.StatusOK, &ret)
}

// RouteName ...