Restful API used gin-swagger and oauth2,can not get the client_id,client_secret from the post request.
lulouis opened this issue · 5 comments
lulouis commented
Describe the bug
Like the next picture,marked some question
To Reproduce
- I defined the authorization type "OAuth2Application".
// @securitydefinitions.oauth2.application OAuth2Application
// @tokenUrl http://localhost:8080/oauth2/token
// @scope.write Grants write access
// @scope.admin Grants read and write access to administrative information
- I defined the action with some paramater ,especially this '@Security'
// ListAccounts godoc
// @Summary Get all account as a list [auth token]
// @Description get accounts
// @Tags accounts
// @Accept json
// @Produce json
// @Param q query string false "name search by q" Format(email)
// @Success 200 {array} model.Account
// @Failure 400 {object} httputil.HTTPError
// @Failure 404 {object} httputil.HTTPError
// @Failure 500 {object} httputil.HTTPError
// @Security OAuth2Application [admin]
// @Router /accounts [get]
func (c *Controller) ListAccounts(ctx *gin.Context) {
q := ctx.Request.URL.Query().Get("q")
accounts, err := model.AccountsAll(q)
if err != nil {
httputil.NewError(ctx, http.StatusNotFound, err)
return
}
ctx.JSON(http.StatusOK, accounts)
}
- cmd input 'swag init ',after that I get a Restful API server.
- Browder my site http://localhost:8080/swagger/index.html,
when I click the 'Authorize' button,I get this bug.
lulouis commented
there are my sourcecode repository.
https://github.com/lulouis/gin-auth2-swagger-demo
easonlin404 commented
I will look this issue asap.
lulouis commented
I will look this issue asap.
Thank you very much.I am standing by for your reply.
lulouis commented
Dear Eason,
I am waiting for your solution yet . Do you need some screenshot or code any more ?
I would like to answer you at all times.Thank you so much.
lulouis commented
Eason,
Thank you , I corrected this issue, it is worked now.
Reference : swagger-api/swagger-ui#4533.
let form = { grant_type: "client_credentials", scope: scopes.join(scopeSeparator), client_id: clientId, //need line client_secret: clientSecret //need line }