Comments (6)
Sure, I can do that. I don't think the error is related to the project itself btw.
from jwt-scala.
I'm not 100% sure, but those functions are protected
, so it should mean that if you extend the object, you will have access to them and then you can freely expose them.
The idea was to only publicly expose "safe" functions which include validation. And if someone wanted to do some dangerous stuff, it would need to kind of override the default feature to allow that. That's why they are protected
rather than private
.
Would that work for you?
from jwt-scala.
I like that idea, but my understanding is that Scala does not allow you to directly extend an object. But if it were a trait then I would be able to. Does that sound right to you?
https://stackoverflow.com/q/7625040/1080804
from jwt-scala.
Maybe? Sorry, it's been years since I have done any Scala. One way of solving it would be to make all current object
as trait
and then create an empty object extending it. This way, you could also freely extend those traits in your own code if needed.
The other solution is to just make them public et let people be responsible :-)
Do you have a preference? Would you consider doing a PR? I don't really have time to code and test Scala code right now.
from jwt-scala.
sorry I didn't get back to you on this. There is a very simple fix: just adding Option[String]
variable to your JwtHeader case class. "kid" is an optional header claim, and so it's probably best to include it.
However, I was never able to run tests. I always hit this issue:
java.util.NoSuchElementException: head of empty stream at com.typesafe.sbt.SbtGit
The PR would be simple though:
case class JwtHeader(
algorithm: Option[JwtAlgorithm] = None,
typ: Option[String] = None,
contentType: Option[String] = None,
keyId: Option[String] = None
) {
def toJson: String = JwtUtils.hashToJson(Seq(
"typ" -> typ,
"alg" -> algorithm.map(_.name).orElse(Option("none")),
"cty" -> contentType
"kid" -> keyId
).collect {
case (key, Some(value)) => (key -> value)
})
/** Assign the kid to the header */
def withKeyId(kid: String): JwtHeader = this.copy(kid = Option(kid))
/** Assign the type to the header */
def withType(typ: String): JwtHeader = this.copy(typ = Option(typ))
/** Assign the default type `JWT` to the header */
def withType: JwtHeader = this.withType(JwtHeader.DEFAULT_TYPE)
}
object JwtHeader {
val DEFAULT_TYPE = "JWT"
def apply(algorithm: Option[JwtAlgorithm]): JwtHeader = algorithm match {
case Some(algo) => JwtHeader(algo)
case _ => new JwtHeader(None, None)
}
def apply(algorithm: JwtAlgorithm): JwtHeader = new JwtHeader(Option(algorithm), Option(DEFAULT_TYPE))
def apply(algorithm: JwtAlgorithm, typ: String): JwtHeader = new JwtHeader(Option(algorithm), Option(typ))
def apply(algorithm: JwtAlgorithm, typ: String, contentType: String): JwtHeader =
new JwtHeader(Option(algorithm), Option(typ), Option(contentType))
def apply(algorithm: JwtAlgorithm, typ: String, contentType: String, keyId: String): JwtHeader =
new JwtHeader(Option(algorithm), Option(typ), Option(contentType), Option(keyId))
}
from jwt-scala.
Done in 0.16.0
from jwt-scala.
Related Issues (20)
- The Issuer needs to be able to extract the URI. HOT 1
- KeyId ('kid') of JWT header is not parsed HOT 1
- Inconsistent processing of malformed 'content' field of a claim HOT 1
- Reopen old issue and provide support for encryption and decryption in addition to signing(existing)
- Add support for scope claim
- Wrong version in docs HOT 2
- Add support for ZIO-JSON library
- Extract Audience while decoding into JwtClaim HOT 3
- Add zio-json usage documentation
- com.fasterxml.jackson.databind.JsonMappingException: Scala module 2.11.4 requires Jackson Databind version >= 2.11.0 and < 2.12.0 HOT 10
- 9.1.1 changelog? HOT 2
- zio-json partially missing in the docs
- com.fasterxml.jackson.databind.JsonMappingException: Scala module 2.11.4 requires Jackson Databind version >= 2.11.0 and < 2.12.0 HOT 2
- Why does JwtCirce.decode lead to java.time.Clock validating the expiration? HOT 3
- [Question] Support for Base64 url encoded keys HOT 1
- [Question] Lookup the algorithm from the token
- fix scala-js build HOT 5
- Ed25519 is not the correct JSON Web Algorithm name
- parseKey does not work with keys stored in AWS secrets manager
- Version 9.4.0 is not compatible with Scala 3.2.2 HOT 6
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 jwt-scala.