-
-
Notifications
You must be signed in to change notification settings - Fork 934
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add jwt
to internet
module
#1282
Comments
What would be the benefit of a generated invalid token over a static expired one? |
Just so I understand you correctly. You suggest doing the following:
This is not possible for me because the part where I write the documentation doesn't depend on the implementation of the JWT generation (or any business logic tbh). So I'm not able to access One more thing: |
I'd be interested in Faker having this too. |
Please upvote the issue if you are interested in having this in Faker. That way we can track user interest. |
Silly question but how do I upvote? |
With "upvote" we mean the But I saw that you already found it 👍 More information on reactions can be found on "Add Reactions to Pull Requests, Issues, and Comments" |
Thank you for your feature proposal. We marked it as "waiting for user interest" for now to gather some feedback from our community:
We would also like to hear about other community members' use cases for the feature to give us a better understanding of their potential implicit or explicit requirements. We will start the implementation based on:
We do this because:
|
An example call could look like: const jwt: string = faker.internet.jwt({
algorithm: faker.internet.jwtAlgorithm(),
refDate: faker.date.past(),
}); But what should be returned? |
Or more specifically: What are your requirements/expectations?
|
Proposal for minimalistic API implementationThe following text uses "Requirement Levels" based on RFC 2119
As stated in my original feature request:
We can asset multiple things here:
Additionally, I suggest that the initial method SHOULD be as minimalistic as possible. The following sections are suggestions that should summarize the higher level implementation details for Headers
Payload
Signature
Example implementationjwt(): string {
const header = {
alg: randomJwtHeaderAlgorythm(), // abstracted here
typ: 'JWT',
};
const payload = {
iat: this.faker.date.anytime().valueOf(),
exp: this.faker.date.anytime().valueOf(),
};
const encodedHeader = Buffer.from(JSON.stringify(header)).toString('base64url');
const encodedPayload = Buffer.from(JSON.stringify(payload)).toString('base64url');
const signature = faker.random.alphaNumeric(64);
return `${encodedHeader}.${encodedPayload}.${signature}`;
}; Feel free to give feedback on the proposal. |
These headers are also optional according to the spec. I didn't find any specifics regarding alg at all.
These claim names are also optional according to the spec.
If it should be as minimalisistic as possible, it should omit all optional fields.
What is your intention doing with such a value? It would be a different matter if you could provide the/additional header and payload entries. Providing a valid signature isn't possible without specific libraries, not available in all environments (e.g. node:crypto) |
My comment was not a summary of RFC7519 but a "Proposal for minimalistic API implementation" (as stated in the first heading) - a suggested specification for the implementation. If this intent was not clear enough, I apologize for that.
While this would be true when strictly following the RFC, I'd argue that real-world use cases nearly always include the "typ" property in the header as well as the properties "exp" and "iat" in the payload. That's the reason why I suggested including them.
As stated in my original comment as well:
Agreed, this is why I made the statements in the suggestion, covering the necessity to not include valid signatures. |
Team Decision
|
I'll get this feature. This is going to be my first, so please be kind. |
Welcome to the project. I assigned the issue to you. |
Clear and concise description of the problem
As a developer, I use faker to "seed" my documentation examples. I was currently writing a section about the usage of the JWT token in my system. For visualization purposes, I wanted to provide an example JWT so developers can see what to expect. Sadly faker doesn't provide such a feature (at least not in the internet module where I would expect it).
Suggested solution
Add a basic
jwt
function to theinternet
module that returns a string that is a JWT. So it should be "decryptable" but has a random signature.I don't think it's necessary to input a payload object since that would get too close to a real implementation (?).
Alternative
Currently, I use a hardcoded JWT (with incorrect signature and expired) for my documentation.
Additional context
No response
Note
This issue has been marked with "good first issue". If you'd like to get started contributing to this project, this is the issue for you! The issue can be solved by following the acceptance criteria layed out in the team decision comment
The text was updated successfully, but these errors were encountered: