Skip to content

Commit

Permalink
Add support for POST & embedded claims struct in the body.
Browse files Browse the repository at this point in the history
Signed-off-by: Ville Aikas <[email protected]>
  • Loading branch information
vaikas committed Apr 8, 2023
1 parent 57175f7 commit f6fc4e2
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# justtrustme

justtrust me is a demo/testing OIDC token issuer. It will accept any claims as query parameters and mint valid OIDC tokens with them.
justtrust me is a demo/testing OIDC token issuer. It will accept any claims as
query parameters (or POST body using JSON encoding) and mint valid OIDC tokens
with them.

Needless to say, __do not trust anything about this__.

Expand All @@ -13,3 +15,22 @@ Interesting endpoints:
- [/.well-known/openid-configuration](https://justtrustme.dev/.well-known/openid-configuration)

`?debug=true` is a special query arg that will render a decoded token.

You can also POST a JSON struct that contains the keys. This allows for embedded
queries for example. As an example:
`curl -X POST 'https://justtrustme.dev/token?debug=true&foo=bar' -d '{"key1":"value1","embedded":{"key2":"value2","key3":"value3"}}'`

Would create the following claims:
```
"payload": {
"embedded": {
"key2": "value2",
"key3": "value3"
},
"exp": 1680999300,
"foo": "bar",
"iat": 1680997500,
"iss": "https://justtrustme.dev",
"key1": "value1"
}
```
19 changes: 19 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"net/http"
"net/url"
"os"
Expand Down Expand Up @@ -133,6 +134,24 @@ func main() {
query := r.URL.Query()
debug := query.Get("debug")
claims := make(map[string]interface{})

// This is fine even if there's no to body sent.
body, err := ioutil.ReadAll(r.Body)
if err != nil {
log.Errorf("error reading body: %w", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

if len(body) > 0 {
err = json.Unmarshal(body, &claims)
if err != nil {
log.Errorf("error unmarshaling: %w", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}

for k, v := range query {
if k == "debug" {
continue
Expand Down

0 comments on commit f6fc4e2

Please sign in to comment.