Created
December 23, 2022 20:42
-
-
Save DmitrySikorsky/45d58df3c4f783889c6a63518c1a5963 to your computer and use it in GitHub Desktop.
This file contains 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
public async Task<ActionResult> IndexAsync(string id_token, string state) | |
{ | |
if (string.IsNullOrEmpty(id_token) || string.IsNullOrEmpty(state) || !state.Contains(';')) | |
return this.BadRequest(); | |
string platform = state.Split(';')[0]; | |
if (!Guid.TryParse(state.Split(';')[1], out Guid emailValidationTokenId)) | |
return this.BadRequest(); | |
EmailValidationToken emailValidationToken = await this.service.GetByIdAsync(emailValidationTokenId); | |
if (emailValidationToken == null) | |
return this.BadRequest(); | |
try | |
{ | |
JwtSecurityToken jwt = new JwtSecurityToken(id_token); | |
emailValidationToken.Email = jwt.Claims.First(c => c.Type == ClaimTypes.Email).Value; | |
} | |
catch | |
{ | |
return this.BadRequest(); | |
} | |
emailValidationToken.Validated = DateTime.Now.ToUniversalTime(); | |
await this.service.EditAsync(emailValidationToken); | |
if (platform == "web") | |
return this.Redirect("https://yourapp.com?token=" + emailValidationTokenId); | |
// Just shows that everything is OK, and the browser window can be closed | |
return this.Redirect("/done"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment