mirror of
https://github.com/fergalmoran/podnoms.git
synced 2026-01-30 20:34:01 +00:00
20 lines
777 B
C#
20 lines
777 B
C#
using System.Linq;
|
|
using System.Security.Claims;
|
|
using System.Threading.Tasks;
|
|
using Newtonsoft.Json;
|
|
using PodNoms.Api.Models;
|
|
|
|
namespace PodNoms.Api.Services.Auth {
|
|
public class Tokens {
|
|
public static async Task<string> GenerateJwt(ClaimsIdentity identity, IJwtFactory jwtFactory, string userName,
|
|
JwtIssuerOptions jwtOptions, JsonSerializerSettings serializerSettings) {
|
|
var response = new {
|
|
id = identity.Claims.Single(c => c.Type == "id").Value,
|
|
auth_token = await jwtFactory.GenerateEncodedToken(userName, identity),
|
|
expires_in = (int)jwtOptions.ValidFor.TotalSeconds
|
|
};
|
|
|
|
return JsonConvert.SerializeObject(response, serializerSettings);
|
|
}
|
|
}
|
|
} |