Open
Changes from all commits
File filter
Filter by extension
Conversations
Failed to load comments.
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Failed to load files.
Uh oh!
There was an error while loading. Please reload this page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
namespace GitCredentialManager.Authentication.Oauth.Json | ||
{ | ||
public class WebToken(WebToken.TokenHeader header, WebToken.TokenPayload payload, string signature) | ||
{ | ||
public class TokenHeader | ||
{ | ||
[JsonRequired] | ||
[JsonInclude] | ||
[JsonPropertyName("typ")] | ||
public string Type { get; private set; } | ||
} | ||
public class TokenPayload | ||
{ | ||
[JsonRequired] | ||
[JsonInclude] | ||
[JsonPropertyName("exp")] | ||
public long Expiry { get; private set; } | ||
} | ||
public TokenHeader Header { get; } = header; | ||
public TokenPayload Payload { get; } = payload; | ||
public string Signature { get; } = signature; | ||
public bool IsExpired | ||
{ | ||
get | ||
{ | ||
return Payload.Expiry < DateTimeOffset.Now.ToUnixTimeSeconds(); | ||
} | ||
} | ||
static public bool TryCreate(string value, out WebToken jwt) | ||
{ | ||
jwt = null; | ||
try | ||
{ | ||
var parts = value.Split('.'); | ||
if (parts.Length != 3) | ||
{ | ||
return false; | ||
} | ||
var header = JsonSerializer.Deserialize<TokenHeader>(Base64UrlConvert.Decode(parts[0])); | ||
if (!"JWT".Equals(header.Type)) | ||
{ | ||
return false; | ||
} | ||
var payload = JsonSerializer.Deserialize<TokenPayload>(Base64UrlConvert.Decode(parts[1])); | ||
jwt = new WebToken(header, payload, parts[2]); | ||
return true; | ||
} | ||
catch | ||
{ | ||
return false; | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.