Skip to content

Commit

Permalink
fix decrypt
Browse files Browse the repository at this point in the history
  • Loading branch information
Lightczx committed Feb 6, 2024
1 parent 7385017 commit beadaa7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.IdentityModel.Tokens.Jwt;
using System.Net.Http.Headers;
using System.Security.Cryptography;
using System.Security.Policy;

namespace Snap.Hutao.Server.Controller;

Expand Down Expand Up @@ -80,15 +81,20 @@ public async Task<IActionResult> RedirectLoginAsync([FromQuery(Name = "token")]
[HttpGet("Authorize")]
public async Task<IActionResult> HandleAuthorizationCallbackAsync([FromQuery(Name = "code")] string code, [FromQuery(Name = "state")] string state)
{
if (string.IsNullOrEmpty(code) || string.IsNullOrEmpty(state))
if (string.IsNullOrEmpty(code))
{
return RedirectToError(ReturnCode.GithubAuthrizationCanceled);
}

if (string.IsNullOrEmpty(state))
{
return RedirectToError(ReturnCode.InvalidQueryString);
}

UserIdentity? userIdentity;
try
{
userIdentity = JsonSerializer.Deserialize<UserIdentity>(DecryptState(state));
userIdentity = JsonSerializer.Deserialize<UserIdentity>(DecryptState(Uri.UnescapeDataString(state)));
ArgumentNullException.ThrowIfNull(userIdentity);
}
catch (Exception)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public enum ReturnCode
InternalGithubAuthException = 514004,
InvalidGithubAuthState = 514005,
GithubAlreadyAuthorized = 514006,
GithubAuthrizationCanceled = 514007,
ReCaptchaVerifyFailed = 515001,
ServiceKeyInvalid = 516001,
UserNameNotExists = 516002,
Expand Down

0 comments on commit beadaa7

Please sign in to comment.