Package: httpie-oauth2-client-credentials
hca-httpie-authAs an auth plugin for httpie, it obtains a token with the OAuth2.0 client_credentials flow before executing http, and adds theAuthorization: Bearer ${token}header to the executed request.Token request patternsToken request patterns are supported for the following:Installationpipinstallhttpie-oauth2-client-credentialsUsageSince the format of the request to get the token depends on the support of the server, this module supports the following three patterns depending on the--token-request-typeoption.The SCOPE parameter is optional in all patterns.Basic authentication (default)Set CLIENT_ID and CLIENT_SECRET to Basic authentication to get the token.Since this pattern is the default, you can omit the--token-request-typeoption.Execute command:http--auth-type=oauth2-client-credentials\--auth="${CLIENT_ID}:${CLIENT_SECRET}"\--token-endpoint="${TOKEN_ENDPOINT_URL}"\--token-request-type="basic"\--scope="${SCOPE}"\${TARGET_ENDPOINT_URL}Token request:POST ${TOKEN_ENDPOINT_URL} HTTP/1.1
Host: ${TOKEN_ENDPOINT_HOST}
Authorization: Basic ${CLIENT_ID:CLIENT_SECRET base64 strings}
Content-Type: application/x-www-form-urlencoded

grant_type=client_credentials
&scope=${SCOPE}Form request (application/x-www-form-urlencoded)Send CLIENT_ID and CLIENT_SECRET as part of the Form data.Execute command:http--auth-type=oauth2-client-credentials\--auth="${CLIENT_ID}:${CLIENT_SECRET}"\--token-endpoint="${TOKEN_ENDPOINT_URL}"\--token-request-type="form"\--scope="${SCOPE}"\${TARGET_ENDPOINT_URL}Token request:POST ${TOKEN_ENDPOINT_URL} HTTP/1.1
Host: ${TOKEN_ENDPOINT_HOST}
Content-Type: application/x-www-form-urlencoded

client_id=${CLIENT_ID}
&client_secret=${CLIENT_SECRET}
&grant_type=client_credentials
&scope=${SCOPE}JSON request (application/json)Sends all request properties as JSON format.Execute command:http--auth-type=oauth2-client-credentials\--auth="${CLIENT_ID}:${CLIENT_SECRET}"\--token-endpoint="${TOKEN_ENDPOINT_URL}"\--token-request-type="json"\--scope="${SCOPE}"\${TARGET_ENDPOINT_URL}Token request:POST ${TOKEN_ENDPOINT_URL} HTTP/1.1
Host: ${TOKEN_ENDPOINT_HOST}
Content-Type: application/json

{
    "client_id": "${client_id}",
    "client_secret": "${client_secret}",
    "grant_type": "client_credentials",
    "scope": "${SCOPE}"
}Supported .netrcSupported.netrc.Please check thehttpie documentationfor usage instructions.Important Notes before UseThe value for "machine" in the ".netrc" file is the TARGET_ENDPOINT host, not the TOKEN_ENDPOINT host.
It should be TOKEN_ENDPOINT, but the main body of httpie is designed to extract authentication information from the TARGET_ENDPOINT host.# Create(or add) .netrc file.cat<<EOF>> ~/.netrcmachine   {TARGET_ENDPOINT_HOST}login     {Your Client ID}password  {Your Client Secret}EOF# Change permission.chmod600~/.netrc# Example request.http--auth-type=oauth2-client-credentials\--token-endpoint="${TOKEN_ENDPOINT_URL}"\--token-request-type="form"\--scope="${SCOPE}"\${TARGET_ENDPOINT_URL}Options--print-token-responseOutput the token acquisition response to the consoleNoteToken responseThe token response must be JSON in the following format.The format to be given to the Authorization header of the target endpoint is${token_type} ${access_token}.Iftoken_typeis not included in the response, the default value of the Prefix isBearer.{"token_type":"Bearer","access_token":"xxxxxxxxxxxx","expires_in":3599}CautionThis plugin does not have a function to cache the token until "expires_in", so it will send a token request every time you execute the http command.