Skip to content

Instantly share code, notes, and snippets.

@DmitrySikorsky
Created December 23, 2022 20:42
Show Gist options
  • Save DmitrySikorsky/45d58df3c4f783889c6a63518c1a5963 to your computer and use it in GitHub Desktop.
Save DmitrySikorsky/45d58df3c4f783889c6a63518c1a5963 to your computer and use it in GitHub Desktop.
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