Comments (4)
I'm guessing your question is
- RegisterCustomField is what you think should work, but
- since it requires a concrete type, it doesn't work on the interface type
jwk.Key
- So how should I go about parsing it?
This is sort of an escape hatch, but I think I would do (untested, but I think it should work):
package myapp
type EmbeddedKey struct {
Key jwk.Key
}
func (k *EmbeddedKey) UnmarshalJSON(data []byte) error {
parsed, err := jwk.ParseKey(data)
if err != nil { return err }
k.Key = parsed
return nil
}
// elsewhere...
jwt.RegisterCustomField(`key`, EmbeddedKey{})
tok, err := jwt.Parse(...)
k, _ := tok.Get(`key`)
// use k.Key
(this is mainly a note for my future self): For when/if there's v3, I think it would be prudent to allow RegisterCustomField
to accept a constructor/parser, if that's possible.
from jwx.
RegisterCustomField
accepting a parser would be great and solve my issue!
Also thanks for coming up with this workaround. Using the wrapper type for unmarshalling works great!
from jwx.
This issue is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 7 days.
from jwx.
This issue was closed because it has been stalled for 7 days with no activity. This does not mean your issue is rejected, but rather it is done to hide it from the view of the maintains for the time being. Feel free to reopen if you have new comments
from jwx.
Related Issues (20)
- Example of decrypting a JWT? HOT 1
- jwt.ParseInsecure return verification error HOT 4
- jws.UnregisterSigner does not remove the underlying signer from the global signers map HOT 4
- `WithInferAlgorithmFromKey` should cache inferences alas HOT 3
- Simple custom field on a JWT token HOT 5
- Update go version within go.mod
- `jwk.SetGlobalFetcher` requires object implementing interface with unexported methods HOT 19
- Expose function to check if `jws.Verify` failed with `verifyError` or not HOT 6
- [v3] Deprecate jwk's global fetcher
- [doc] CVE-2024-21664 - Missing v1 fix version HOT 9
- [v1][v2] Add option to disallow JSON format for JWTs HOT 2
- Disabling kid check with jws.Verify on a JWKSet HOT 2
- jwt.ParseRequest should also look for the token in cookies HOT 3
- How to Sign a jwt token with just a string and not publicKey and privateKey HOT 2
- [v2] Accessing registered claims during verification (keyprovider) HOT 6
- Support the new fully-specified JOSE algorithms HOT 2
- Support for custom key usage types in JWKs HOT 3
- Ability to work with PEM/DER for secp256k1 HOT 14
- jwx command-line tool does not support PEM output for secp256k1 HOT 2
- [v3] Change KeyUsageType's Accept behavior to be by default strict, and allow toggling the feature
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jwx.