Documenting POST endpoint using base64 encoding
See original GitHub issueHi, I am trying to document an enpoint that encodes 2 variables. Is it possible to use base64? I know how to do it under security definitions, but we need to have it fully documented as a standalone POST/.
POST: /v1/url HTTP/1.1
Host: host.api
Content-Type: application/x-www-form-urlencoded
Authorization: Basic base64(*CLIENT_ID_VALUE* + “:” + *CLIENT_SECRET_VALUE*)
grant_type=client_credentials
Thanks!
Issue Analytics
- State:
- Created 5 years ago
- Comments:16 (8 by maintainers)
Top Results From Across the Web
File upload as JSON base64 encoded - YouTube
This tutorial takes a look at how you can upload a file and send it as a JSON payload encoded in base64.Commands used...
Read more >How to upload files from your HTML form using Base64 ...
Learn how to quickly encode your file input content as Base64 Data URI and save it to your server.
Read more >Post an image(base64 encoded string) directly to i...
Post an image(base64 encoded string) directly to image type field on form using REST API. step-2 : Select any image that you want...
Read more >Base64 Encoding | Cloud Vision API - Google Cloud
You can provide image data to the Vision API by specifying the URI path to the image, or by sending the image data...
Read more >How to send a base64 encoded image to a FastAPI backend?
As described in this answer, uploaded files are sent as form data. As per FastAPI documentation: Data from forms is normally encoded using...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for the detailed walkthrough @hkosova. My swagger doc has security and securityDefinitions defined. I was trying to document the /post for the token request outside the pop-up window, in details. For now, I ended up removing the Try Out button from it, to still keep the endpoint documentation visible but hiding any working logic around it, so if someone is exploring the API docs and they don’t want to try them, they can still read the /post logic outside the Authorize pop-up.
@Yaima In this scenario, client ID and client secret cannot (and should not) be described as
parameters
.Authorization: Basic base64(value1:value2)
request header is handled by security definitions instead. Here’s a more detailed example:To test the API call in Swagger UI, click the authorize button and enter the client ID and secret in the authorization dialog. They send the request. The request will be sent with the properly encoded
Authorization
header. The security definition (TokenRequestBasicAuth
) is responsible for constructing theAuthorization
header.This is how it can be done using standard OpenAPI syntax and vanilla Swagger UI.
If you mean you want to display
client_id
andclient_secret
in the Parameters list instead (along withgrant_type
), then you’ll need to implement custom logic in your Swagger UI. For example, you could use extension properties (x-...
) to describe the client ID and secret, like so:and add code that would display them and then build the
Authorization
header based on their values. @shockey might have more ideas about how such customization could be implemented.