Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ Configuration options:
* `authHeader` - The name of the request header containing the JWT. Defaults to "Authorization".
- Requires the Bearer token format e.g {authHeader} Bearer {jwt}
* `accessHeader` - The name of the header to inject with the wallet access JSON. Defaults to "x-wallet-access". Only injected when rbac configuration is set
* `senderHeader` - The name of the header to inject with the addr claim of the user signed JWT. If not set then will not inject
* `senderHeader` - The name of the header to inject with the `addr` claim of the user signed JWT. If not set then will not inject
* `publicKeyHeader` - The name of the header to inject with the public key (`sub` claim) of the wallet. If not set then will not inject.

*= Required to get delegated access rights

Expand Down
2 changes: 2 additions & 0 deletions cmd/jwt-wallet/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,12 @@ func TestValidJwt(t *testing.T) {
})
assert.NoError(t, err)

config.PublicKeyHeader = "x-wallet-public-key"
env.DoHttp(config)

assert.Equal(t, 200, env.ClientRes.Status)
assert.NotEmpty(t, env.ServiceReq.Headers.Get("x-wallet-access"))
assert.Equal(t, env.ServiceReq.Headers.Get("x-wallet-public-key"), claims.Subject)
assert.Empty(t, env.ServiceReq.Headers.Get("x-sender"))
assert.Equal(t, subjectJSONString, env.ServiceReq.Headers.Get("x-wallet-access"))
}
Expand Down
16 changes: 11 additions & 5 deletions jwt-wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ import (
)

type Config struct {
RBAC string `json:"rbac"`
APIKey string `json:"apikey"`
AuthHeader string `json:"authHeader"`
AccessHeader string `json:"accessHeader"`
SenderHeader string `json:"senderHeader"`
RBAC string `json:"rbac"`
APIKey string `json:"apikey"`
AuthHeader string `json:"authHeader"`
AccessHeader string `json:"accessHeader"`
SenderHeader string `json:"senderHeader"`
PublicKeyHeader string `json:"publicKeyHeader"`
}

func New() interface{} {
Expand Down Expand Up @@ -83,6 +84,7 @@ func (conf Config) Access(kong *pdk.PDK) {
kong.Response.Exit(500, "something went wrong", x)
return
}

if conf.AccessHeader == "" {
conf.AccessHeader = "x-wallet-access"
}
Expand All @@ -95,6 +97,10 @@ func (conf Config) Access(kong *pdk.PDK) {
kong.ServiceRequest.SetHeader(conf.SenderHeader, sender)
}

if conf.PublicKeyHeader != "" {
kong.ServiceRequest.SetHeader(conf.PublicKeyHeader, tok.Claims.(*signing.Claims).Subject)
}

kong.Log.Warn(tok)

}
Expand Down