From ddd180981c29c743387243ba0aca20349ab5b4e2 Mon Sep 17 00:00:00 2001 From: Rob Kennedy Date: Tue, 4 May 2021 22:53:28 -0400 Subject: [PATCH] Added additional ToClaimFormat extension for converting an address back to a JWT JSON formatted address. --- src/Extensions/ContactExtensions.cs | 20 ++++++++++++++++++++ src/Talegen.Common.Models.csproj | 4 ++-- src/Talegen.Common.Models.xml | 16 +++++++++++++++- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/Extensions/ContactExtensions.cs b/src/Extensions/ContactExtensions.cs index c53a38a..363f82c 100644 --- a/src/Extensions/ContactExtensions.cs +++ b/src/Extensions/ContactExtensions.cs @@ -84,5 +84,25 @@ public static Address ToAddress(this string claimValue) return result; } + + /// + /// Converts the specified Address model to JWT Address format. + /// + /// The address to convert. + /// Returns a JWT address formatted JSON model string. + public static string ToClaimFormat(this Address address) + { + JwtAddressModel jwtAddressModel = new JwtAddressModel + { + Country = address.Country, + Locality = address.City, + PostalCode = address.PostalCode, + Region = address.RegionState, + StreetAddress = address.Street1 + (!string.IsNullOrWhiteSpace(address.Street2) ? Environment.NewLine + address.Street2 : string.Empty), + Formatted = address.Formatted + }; + + return JsonConvert.SerializeObject(jwtAddressModel); + } } } \ No newline at end of file diff --git a/src/Talegen.Common.Models.csproj b/src/Talegen.Common.Models.csproj index 6d217e3..876bc0d 100644 --- a/src/Talegen.Common.Models.csproj +++ b/src/Talegen.Common.Models.csproj @@ -13,10 +13,10 @@ https://github.com/Talegen/Talegen.Common.Models git Models - Added additional ToAddress extension method for string claim values. + Added additional ToClaimFormat extension for converting an address back to a JWT JSON formatted address. Assets\logo.ico false - 1.0.4.0 + 1.0.5.0 en diff --git a/src/Talegen.Common.Models.xml b/src/Talegen.Common.Models.xml index a9c3844..c620ce8 100644 --- a/src/Talegen.Common.Models.xml +++ b/src/Talegen.Common.Models.xml @@ -604,9 +604,23 @@ This extension method converts a JWT address claim to a model object. The claim containing the address information. - + Returns a new Address model containing found claim address details. Exception is thrown if is null. + + + This extension method converts a JWT address claim to a model object. + + The claim value containing the address information. + Returns a new Address model containing found claim address details. + + + + Converts the specified Address model to JWT Address format. + + The address to convert. + Returns a JWT address formatted JSON model string. + This class represents a JWT address model for use in translation to a model.