-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_access_token_request.go
61 lines (51 loc) · 1.54 KB
/
api_access_token_request.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
* NRF OAuth2
*
* NRF OAuth2 Authorization
*
* API version: 1.0.0
* Generated by: OpenAPI Generator (https://openapi-generator.tech)
*/
package accesstoken
import (
"github.com/nycu-ucr/gonet/http"
"github.com/nycu-ucr/gin"
"github.com/nycu-ucr/http_wrapper"
"github.com/nycu-ucr/nrf/logger"
"github.com/nycu-ucr/nrf/producer"
"github.com/nycu-ucr/openapi"
"github.com/nycu-ucr/openapi/models"
)
// AccessTokenRequest - Access Token Request
func HTTPAccessTokenRequest(c *gin.Context) {
logger.AccessTokenLog.Infoln("In HTTPAccessTokenRequest")
var accessTokenReq models.AccessTokenReq
// logger.AccessTokenLog.Infoln("Content Type: ", c.ContentType())
err := c.Bind(&accessTokenReq)
if err != nil {
problemDetail := "[Request Body] " + err.Error()
rsp := models.ProblemDetails{
Title: "Malformed request syntax",
Status: http.StatusBadRequest,
Detail: problemDetail,
}
logger.AccessTokenLog.Warnln(problemDetail)
c.JSON(http.StatusBadRequest, rsp)
return
}
req := http_wrapper.NewRequest(c.Request, accessTokenReq)
req.Params["paramName"] = c.Params.ByName("paramName")
httpResponse := producer.HandleAccessTokenRequest(req)
responseBody, err := openapi.Serialize(httpResponse.Body, "application/json")
if err != nil {
logger.AccessTokenLog.Warnln(err)
problemDetails := models.ProblemDetails{
Status: http.StatusInternalServerError,
Cause: "SYSTEM_FAILURE",
Detail: err.Error(),
}
c.JSON(http.StatusInternalServerError, problemDetails)
} else {
c.JSON(httpResponse.Status, responseBody)
}
}