Hi I have a azure function where I'm trying to get the current id of the user from a jwt token.
I'm currently reading it from the header which makes sense to me but I'm concerned I may not be following best practices.
Also the first line seems a bit hacky to me.
Can you guys please take a look at it and suggest how I can improve this.
Or is this totally the wrong approach?
[FunctionName(nameof(GetDates))]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "dates")]HttpRequest req, ILogger logger, [Table("Date")] CloudTable table
)
{
var token = req.Headers["Authorization"][0].Replace("Bearer ", string.Empty);
var handler = new JwtSecurityTokenHandler();
var jtToken = handler.ReadJwtToken(token);
var userId = jtToken.Payload["Id"].ToString();