| | | 1 | | using ArturRios.Util.WebApi.Security.Interfaces; |
| | | 2 | | using ArturRios.Util.WebApi.Security.Records; |
| | | 3 | | using Google.Apis.Auth; |
| | | 4 | | |
| | | 5 | | namespace ArturRios.Util.WebApi.Security.Authentication; |
| | | 6 | | |
| | | 7 | | /// <summary>Default <see cref="IGoogleTokenVerifier"/> backed by <see cref="GoogleJsonWebSignature"/>, which fetches an |
| | | 8 | | public class GoogleTokenVerifier : IGoogleTokenVerifier |
| | | 9 | | { |
| | | 10 | | /// <inheritdoc /> |
| | | 11 | | public async Task<GoogleTokenPayload?> VerifyAsync(string token, IEnumerable<string> audiences) |
| | 0 | 12 | | { |
| | 0 | 13 | | if (string.IsNullOrWhiteSpace(token)) |
| | 0 | 14 | | { |
| | 0 | 15 | | return null; |
| | | 16 | | } |
| | | 17 | | |
| | | 18 | | try |
| | 0 | 19 | | { |
| | 0 | 20 | | var settings = new GoogleJsonWebSignature.ValidationSettings { Audience = audiences }; |
| | 0 | 21 | | var payload = await GoogleJsonWebSignature.ValidateAsync(token, settings); |
| | | 22 | | |
| | 0 | 23 | | return new GoogleTokenPayload(payload.Email ?? string.Empty, payload.Subject ?? string.Empty, payload.EmailV |
| | | 24 | | } |
| | 0 | 25 | | catch (InvalidJwtException) |
| | 0 | 26 | | { |
| | 0 | 27 | | return null; |
| | | 28 | | } |
| | 0 | 29 | | } |
| | | 30 | | } |