We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Improve the documentation, especially around the use of the keys.
See here for an example.
Excerpt:
...
I'm using Paseto.Core Nuget from https://github.com/daviddesmet/paseto-dotnet, and I'm trying to create v4 public PASETO token with this. My code:
public async Task<TokenResponse> GenerateAsync(Client client, TokenRequest tokenRequest, string issuer, string audience) { var privateEd25519Key = await File.ReadAllBytesAsync("private.pem"); var pasetoToken = new PasetoBuilder() .Use(ProtocolVersion.V4, Purpose.Public) .WithKey(privateEd25519Key, Encryption.AsymmetricSecretKey) .Issuer(issuer) .Subject(tokenRequest.ClientId) .Audience(audience) .NotBefore(DateTime.UtcNow) .IssuedAt(DateTime.UtcNow) .Expiration(DateTime.UtcNow.AddSeconds(client.AccessTokenLifetime)) .TokenIdentifier(Guid.NewGuid().ToString()) .AddClaim("client_id", tokenRequest.ClientId) .AddClaim("scopes", tokenRequest.Scopes) .Encode(); return new TokenResponse { AccessToken = pasetoToken, Lifetime = client.AccessTokenLifetime, Scope = tokenRequest.Scopes }; } }
Besides, due to the rather unclear documentation, I don't know if I'm really creating a token signed with a private key or encrypted.
Here is my solution:
public async Task<TokenResponse> GenerateAsync(Client client, TokenRequest tokenRequest, string issuer, string audience) { var ed25519pkcs8 = await File.ReadAllTextAsync("private.pem"); var privatePemReader = new PemReader(new StringReader(ed25519pkcs8)); var ed25519pkcs8Parameters = (Ed25519PrivateKeyParameters)privatePemReader.ReadObject(); ISigner signer = new Ed25519Signer(); signer.Init(true, ed25519pkcs8Parameters); var pasetoToken = new PasetoBuilder() .Use(ProtocolVersion.V4, Purpose.Public) .WithKey(signer.GenerateSignature(), Encryption.AsymmetricSecretKey) .Issuer(issuer) .Subject(tokenRequest.ClientId) .Audience(audience) .NotBefore(DateTime.UtcNow) .IssuedAt(DateTime.UtcNow) .Expiration(DateTime.UtcNow.AddSeconds(client.AccessTokenLifetime)) .TokenIdentifier(Guid.NewGuid().ToString()) .AddClaim("client_id", tokenRequest.ClientId) .AddClaim("scopes", tokenRequest.Scopes) .Encode(); return new TokenResponse { AccessToken = pasetoToken, Lifetime = client.AccessTokenLifetime, Scope = tokenRequest.Scopes }; }
It turned out that WithKey doesn't support PEM files, so you had to get the private key out of PKCS#8.
The text was updated successfully, but these errors were encountered:
daviddesmet
No branches or pull requests
Improve the documentation, especially around the use of the keys.
See here for an example.
Excerpt:
...
...
The text was updated successfully, but these errors were encountered: