Skip to content

Commit

Permalink
last minute change, return the token as a json object with key "token"
Browse files Browse the repository at this point in the history
  • Loading branch information
maxxfrazer committed Jul 26, 2023
1 parent f05b120 commit 8625bfc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,10 @@ The following are the supported token types along with their required parameters

### Response

Upon successful generation of the token, the API will respond with an HTTP status code of `200 OK`, and the response body will contain the token in plain text.
Upon successful generation of the token, the API will respond with an HTTP status code of `200 OK`, and the response body will contain the token in a JSON key `"token"`.

If there is an error during token generation or if the request parameters are invalid, the API will respond with an appropriate HTTP status code and an error message in the response body.


### Sample Usage

Here's an example of how to use the `getToken` API endpoint with a POST request using cURL:
Expand All @@ -147,8 +146,10 @@ curl -X POST -H "Content-Type: application/json" -d '{

#### Reponse:

```text
007hbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJhZG1pbiIsInN1YiI6InVzZXIxMjMiLCJpYXQiOjE2MzEwNTU4NzIsImV4cCI6MTYzMTA1OTQ3Mn0.3eJ-RGwIl2ANFbdv4SeHtWzGiv6PpC3i0UqXlHfsqEw
```json
{
"token": "007hbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJhZG1pbiIsInN1YiI6InVzZXIxMjMiLCJpYXQiOjE2MzEwNTU4NzIsImV4cCI6MTYzMTA1OTQ3Mn0.3eJ-RGwIl2ANFbdv4SeHtWzGiv6PpC3i0UqXlHfsqEw"
}
```

---
Expand Down
5 changes: 3 additions & 2 deletions service/http_handlers_POST.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ func (s *Service) getToken(c *gin.Context) {
c.JSON(http.StatusBadRequest, gin.H{"error": tokenErr.Error()})
return
}
c.Writer.WriteHeader(http.StatusOK)
c.Writer.Write([]byte(token))
c.JSON(http.StatusOK, gin.H{
"token": token,
})
}

// TokenRequest is a struct representing the JSON payload structure for token generation requests.
Expand Down

0 comments on commit 8625bfc

Please sign in to comment.