https://github.com/dxps/s2s_auth_srv
A minimal OAuth2 Server that supports Client Credentials Flow, plus a small and specific use case.
https://github.com/dxps/s2s_auth_srv
Last synced: 7 months ago
JSON representation
A minimal OAuth2 Server that supports Client Credentials Flow, plus a small and specific use case.
- Host: GitHub
- URL: https://github.com/dxps/s2s_auth_srv
- Owner: dxps
- Created: 2021-07-08T12:07:26.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2021-07-15T09:56:27.000Z (about 5 years ago)
- Last Synced: 2025-10-08T22:07:33.791Z (10 months ago)
- Language: Go
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
## Service-to-Service OAuth2 Auth Server
This sample supports OAuth2 Client Credentials Flow, relevant for service to service comm.
### Usage
Create/get a set of credentials:
```shell
$ curl http://localhost:9096/credentials
{"CLIENT_ID":"da374969","CLIENT_SECRET":"a71ba2f0"}
$
```
Authenticate to get an access token:
```shell
$ curl 'http://localhost:9096/token?grant_type=client_credentials&client_id=da374969&client_secret=a71ba2f0'
{
"access_token":"eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiI3M2RlNGViMCIsImV4cCI6MTYyNTc2MDE2NH0.bAsWHqwmmrk22BisWWkfDicQXnvLdkG7RVm5Y6ITWzC7fyz8fMFsYHnHwGnMWG66OyPaVgAVGLVLgzEEJtijEw",
"expires_in":7200,
"token_type":"Bearer"
}
$
```
According to OAuth2 spec ([section 2.3.1](https://datatracker.ietf.org/doc/html/rfc6749#section-2.3.1)), this is actually not recommended:
> Including the client credentials in the request-body using the two
> parameters is NOT RECOMMENDED and SHOULD be limited to clients unable
> to directly utilize the HTTP Basic authentication scheme (or other
> password-based HTTP authentication schemes).
And considering [section 4.4](https://datatracker.ietf.org/doc/html/rfc6749#section-4.4), the request and response should look as follows. There is no statement saying that request should not include additional params in the body.
- Request:
```
POST /token HTTP/1.1
Host: server.example.com
Authorization: Basic czZCaGRSa3F0MzpnWDFmQmF0M2JW
Content-Type: application/x-www-form-urlencoded
grant_type=client_credentials
```
- Response:
```
HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8
Cache-Control: no-store
Pragma: no-cache
{
"access_token":"2YotnFZFEjr1zCsicMWpAA",
"token_type":"example",
"expires_in":3600,
"example_parameter":"example_value"
}
```