Produced by Araxis Merge on 8/27/2018 1:12:13 PM Central Daylight Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
| # | Location | File | Last Modified |
|---|---|---|---|
| 1 | PPMS Build 8 Sprint 1.zip\PPMS Build 8 Sprint 1\CIF B8S1\VA.PPMS.Plugins\VA.PPMS.Plugins\VA.PPMS.CRM.Plugins\Helper | AddressValidationHelper.cs | Tue Aug 14 18:53:48 2018 UTC |
| 2 | PPMS Build 8 Sprint 1.zip\PPMS Build 8 Sprint 1\CIF B8S1\VA.PPMS.Plugins\VA.PPMS.Plugins\VA.PPMS.CRM.Plugins\Helper | AddressValidationHelper.cs | Wed Aug 15 19:34:37 2018 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 9 | 904 |
| Changed | 8 | 26 |
| Inserted | 0 | 0 |
| Removed | 0 | 0 |
| Whitespace | |
|---|---|
| Character case | Differences in character case are significant |
| Line endings | Differences in line endings (CR and LF characters) are ignored |
| CR/LF characters | Not shown in the comparison detail |
No regular expressions were active.
| 1 | using Syst em; | |
| 2 | using Syst em.Collect ions.Gener ic; | |
| 3 | using Syst em.IO; | |
| 4 | using Syst em.Net; | |
| 5 | using Syst em.Net.Htt p; | |
| 6 | using Syst em.Net.Htt p.Headers; | |
| 7 | using Syst em.Runtime .Serializa tion.Json; | |
| 8 | using Syst em.Securit y.Cryptogr aphy.X509C ertificate s; | |
| 9 | using Syst em.Text; | |
| 10 | using Micr osoft.Xrm. Sdk; | |
| 11 | ||
| 12 | namespace VA.PPMS.CR M.Plugins. Helper | |
| 13 | { | |
| 14 | ||
| 15 | public static cl ass Addres sValidatio nHelper | |
| 16 | { | |
| 17 | pu blic stati c ITracing Service tr acingServi ce; | |
| 18 | ||
| 19 | pu blic stati c RootObje ctResponse ValidateW C(string s treetAddre ss, string city, str ing state, string zi p, ITracin gService _ tracingSer vice) | |
| 20 | { | |
| 21 | try | |
| 22 | { | |
| 23 | trac ingService = _tracin gService; | |
| 24 | ||
| 25 | trac ingService .Trace("Be ginning Ad dress Vali dation"); | |
| 26 | ||
| 27 | trac ingService .Trace("Ad dress Attr ibues for Request:" + streetAd dress + ", " + city + ", " + s tate + ", " + zip); | |
| 28 | var addressDat a = new Ro otObjectRe sponse(); | |
| 29 | ||
| 30 | usin g (MyClien t client = new MyCli ent()) | |
| 31 | { | |
| 32 | client.Hea ders[HttpR equestHead er.Content Type] = "a pplication /json"; | |
| 33 | ||
| 34 | var payloa d = new Ro otObjectRe quest | |
| 35 | { | |
| 36 | reques tAddress = new Addre ss | |
| 37 | { | |
| 38 | ad dressLine1 = streetA ddress, | |
| 39 | ci ty = city, | |
| 40 | st ateProvinc e = new St ateProvinc e | |
| 41 | { | |
| 42 | name = s tate | |
| 43 | }, | |
| 44 | zi pCode5 = z ip | |
| 45 | } | |
| 46 | }; | |
| 47 | var json = Serialize e(payload) ; | |
| 48 | ||
| 49 | tracingSer vice.Trace ("Making C all to Add ress Valid ation Serv ivce"); | |
| 50 | string res ponse = cl ient.Uploa dString(ne w Uri("htt ps://int.v et360. DNS /address-v alidation/ address/v1 /validate" ), json); | |
| 51 | addressDat a = Deseri alize<Root ObjectResp onse>(resp onse); | |
| 52 | if (addres sData != n ull && add ressData.a ddressMeta Data.deliv eryPointVa lidation = = "CONFIRM ED") | |
| 53 | { | |
| 54 | tracin gService.T race("Suce ssful Resp onse from Address Va lidation A PI"); | |
| 55 | } | |
| 56 | tracingSer vice.Trace ("Unsucces sful Respo nse from A ddress Val idation AP I"); | |
| 57 | } | |
| 58 | retu rn address Data; | |
| 59 | } | |
| 60 | catch (W ebExceptio n we) | |
| 61 | { | |
| 62 | trac ingService .Trace("We b Exceptio n on call to Address Validatio n Service: ", we.Mess age.ToStri ng()); | |
| 63 | thro w; | |
| 64 | } | |
| 65 | catch (E xception e ) | |
| 66 | { | |
| 67 | trac ingService .Trace("Ex ception on call to A ddress Val idation Se rvice:", e .ToString( )); | |
| 68 | retu rn null; | |
| 69 | } | |
| 70 | } | |
| 71 | ||
| 72 | pu blic stati c AddressD ata Valida teWcDWS(st ring stree tAddress, string cit y, string state, str ing zip, I TracingSer vice _trac ingService ) | |
| 73 | { | |
| 74 | try | |
| 75 | { | |
| 76 | trac ingService = _tracin gService; | |
| 77 | trac ingService .Trace("Be ginning Ad dress Vali dation"); | |
| 78 | trac ingService .Trace("Ad dress Attr ibues for Request:" + streetAd dress + ", " + city + ", " + s tate + ", " + zip); | |
| 79 | ||
| 80 | var addressDat a = new Ad dressData( ); | |
| 81 | ||
| 82 | usin g (WebClie nt wc = ne w WebClien t()) | |
| 83 | { | |
| 84 | //string a ddressStri ng = "http ://dev.dws .ppms. DNS /v1.0/Vali dateAddres s?streetAd dress="; | |
| 85 | string pro xyAddressS tring = "h ttps://dev .integrati on.d365. DNS /ase/v1.0/ ValidateAd dress?stre etAddress= "; | |
| 86 | ||
| 87 | proxyAddre ssString + = "'" + st reetAddres s + "'"; | |
| 88 | proxyAddre ssString + = "&city=" ; | |
| 89 | proxyAddre ssString + = city; | |
| 90 | proxyAddre ssString + = "&state= "; | |
| 91 | proxyAddre ssString + = state; | |
| 92 | proxyAddre ssString + = "&zip="; | |
| 93 | proxyAddre ssString + = zip; | |
| 94 | proxyAddre ssString = Uri.Escap eUriString (proxyAddr essString) .Replace(" #", "%23") ; | |
| 95 | ||
| 96 | //var test String = " https://de v.dws.ppms . DNS /v1.0/Vali dateAddres s?streetAd dress="; | |
| 97 | ||
| 98 | tracingSer vice.Trace ("Address String: " + proxyAdd ressString ); | |
| 99 | ||
| 100 | wc.Headers [HttpReque stHeader.C ontentType ] = "appli cation/jso n"; | |
| 101 | ||
| 102 | tracingSer vice.Trace ("Making C all to DWS Address V alidation Function") ; | |
| 103 | string dws Response = wc.Downlo adString(p roxyAddres sString); | |
| 104 | AddressDat aValues ad dressDataV alues = De serialize< AddressDat aValues>(d wsResponse ); | |
| 105 | if (addres sDataValue s.value.Co unt > 0) | |
| 106 | { | |
| 107 | tracin gService.T race("Suce ssful Resp onse from Address Va lidation A PI"); | |
| 108 | addres sData = ad dressDataV alues.valu e[0]; | |
| 109 | _traci ngService. Trace("Con fidence Sc ore:" + ad dressData. Confidence Score); | |
| 110 | } | |
| 111 | else | |
| 112 | { | |
| 113 | tracin gService.T race("Unsu ccessful R esponse fr om Address Validatio n API"); | |
| 114 | } | |
| 115 | return add ressData; | |
| 116 | } | |
| 117 | } | |
| 118 | catch (W ebExceptio n we) | |
| 119 | { | |
| 120 | trac ingService .Trace("We b Exceptio n on call to Address Validatio n Service: ", we.Mess age.ToStri ng()); | |
| 121 | retu rn null; | |
| 122 | } | |
| 123 | catch (E xception e ) | |
| 124 | { | |
| 125 | trac ingService .Trace("Ex ception on call to A ddress Val idation Se rvice:", e .ToString( )); | |
| 126 | retu rn null; | |
| 127 | } | |
| 128 | } | |
| 129 | ||
| 130 | pu blic stati c AddressD ata Valida teHttp(str ing street Address, s tring city , string s tate, stri ng zip, IT racingServ ice _traci ngService) | |
| 131 | { | |
| 132 | try | |
| 133 | { | |
| 134 | trac ingService = _tracin gService; | |
| 135 | trac ingService .Trace("Be ginning Ad dress Vali dation"); | |
| 136 | trac ingService .Trace("Ad dress Attr ibues for Request:" + streetAd dress + ", " + city + ", " + s tate + ", " + zip); | |
| 137 | ||
| 138 | var addressDat a = new Ad dressData( ); | |
| 139 | ||
| 140 | usin g (HttpCli ent client = new Htt pClient()) | |
| 141 | { | |
| 142 | //string a ddressStri ng = "http s://dev.dw s.ppms. DNS /v1.0/Vali dateAddres s?streetAd dress="; | |
| 143 | string pro xyAddressS tring = "h ttps://dev .integrati on.d365. DNS /ase/v1.0/ ValidateAd dress?stre etAddress= "; | |
| 144 | ||
| 145 | proxyAddre ssString + = "'1239 V ermont Ave NW #605'" ; | |
| 146 | proxyAddre ssString + = "&city=" ; | |
| 147 | proxyAddre ssString + = "Washing ton"; | |
| 148 | proxyAddre ssString + = "&state= "; | |
| 149 | proxyAddre ssString + = "DC"; | |
| 150 | proxyAddre ssString + = "&zip="; | |
| 151 | proxyAddre ssString + = "20005"; | |
| 152 | proxyAddre ssString = Uri.Escap eUriString (proxyAddr essString) .Replace(" #", "%23") ; | |
| 153 | ||
| 154 | tracingSer vice.Trace ("Making C all to DWS Address V alidation Function") ; | |
| 155 | ||
| 156 | var respon se = clien t.GetStrin gAsync(pro xyAddressS tring).Get Awaiter(). GetResult( ); | |
| 157 | ||
| 158 | AddressDat aValues ad dressDataV alues = De serialize< AddressDat aValues>(r esponse); | |
| 159 | if (addres sDataValue s.value.Co unt > 0) | |
| 160 | { | |
| 161 | tracin gService.T race("Suce ssful Resp onse from Address Va lidation A PI"); | |
| 162 | addres sData = ad dressDataV alues.valu e[0]; | |
| 163 | } | |
| 164 | } | |
| 165 | trac ingService .Trace("Un successful Response from Addre ss Validat ion API"); | |
| 166 | retu rn address Data; | |
| 167 | } | |
| 168 | catch (W ebExceptio n we) | |
| 169 | { | |
| 170 | trac ingService .Trace("We b Exceptio n on call to Address Validatio n Service: ", we.Mess age.ToStri ng()); | |
| 171 | thro w; | |
| 172 | } | |
| 173 | catch (E xception e ) | |
| 174 | { | |
| 175 | trac ingService .Trace("Ex ception on call to A ddress Val idation Se rvice:", e .ToString( )); | |
| 176 | thro w; | |
| 177 | } | |
| 178 | } | |
| 179 | ||
| 180 | pu blic stati c RootObje ctResponse Validate( string str eetAddress , string c ity, strin g state, s tring zip, Microsoft .Xrm.Sdk.I TracingSer vice traci ngService) | |
| 181 | { | |
| 182 | try | |
| 183 | { | |
| 184 | trac ingService .Trace("Be ginning Ad dress Vali dation"); | |
| 185 | //Se rvicePoint Manager.Se rverCertif icateValid ationCallb ack += (se nder, cert ificate, c hain, sslP olicyError s) => true ; | |
| 186 | //Se rvicePoint Manager.Se curityProt ocol = Sec urityProto colType.Tl s12; | |
| 187 | //Se rvicePoint Manager.Se curityProt ocol = Sec urityProto colType.Ss l3 | Secur ityProtoco lType.Tls | Security ProtocolTy pe.Tls11 | SecurityP rotocolTyp e.Tls12; | |
| 188 | ||
| 189 | trac ingService .Trace("Ad dress Attr ibues for Request:" + streetAd dress + ", " + city + ", " + s tate + ", " + zip); | |
| 190 | var addressDat a = new Ro otObjectRe sponse(); | |
| 191 | ||
| 192 | usin g (var cli ent = GetH ttpClient( tracingSer vice)) | |
| 193 | { | |
| 194 | tracingSer vice.Trace ("Setting Client Bas e Address" ); | |
| 195 | ||
| 196 | ||
| 197 | ||
| 198 | client.Bas eAddress = new Uri(" https://in t.vet360. DNS "); | |
| 199 | var payloa d = new Ro otObjectRe quest | |
| 200 | { | |
| 201 | reques tAddress = new Addre ss | |
| 202 | { | |
| 203 | ad dressLine1 = streetA ddress, | |
| 204 | ci ty = city, | |
| 205 | st ateProvinc e = new St ateProvinc e | |
| 206 | { | |
| 207 | name = s tate | |
| 208 | }, | |
| 209 | zi pCode5 = z ip | |
| 210 | } | |
| 211 | }; | |
| 212 | ||
| 213 | var json = Serialize e(payload) ; | |
| 214 | ||
| 215 | var conten t = new St ringConten t(json, En coding.UTF 8, "applic ation/json "); | |
| 216 | content.He aders.Cont entType = new MediaT ypeHeaderV alue("appl ication/js on"); | |
| 217 | ||
| 218 | tracingSer vice.Trace ("Making C all to Add ress Valid ation Serv ivce"); | |
| 219 | var respon se = clien t.PostAsyn c("/addres s-validati on/address /v1/valida te", conte nt).GetAwa iter().Get Result(); | |
| 220 | ||
| 221 | if (respon se.IsSucce ssStatusCo de) | |
| 222 | { | |
| 223 | tracin gService.T race("Suce ssful Resp onse from Address Va lidation A PI"); | |
| 224 | var re sult = res ponse.Cont ent.ReadAs StringAsyn c().GetAwa iter().Get Result(); | |
| 225 | if (!s tring.IsNu llOrEmpty( result)) | |
| 226 | { | |
| 227 | ad dressData = Deserial ize<RootOb jectRespon se>(result ); | |
| 228 | } | |
| 229 | } | |
| 230 | tracingSer vice.Trace ("Unsucces sful Respo nse from A ddress Val idation AP I"); | |
| 231 | } | |
| 232 | retu rn address Data; | |
| 233 | } | |
| 234 | catch (H ttpRequest Exception he) | |
| 235 | { | |
| 236 | trac ingService .Trace("Ht tp Web Exc eption on call to Ad dress Vali dation Ser vice:", he .ToString( )); | |
| 237 | retu rn null; | |
| 238 | } | |
| 239 | catch (E xception e ) | |
| 240 | { | |
| 241 | trac ingService .Trace("Ex ception on call to A ddress Val idation Se rvice:", e .ToString( )); | |
| 242 | thro w; | |
| 243 | } | |
| 244 | } | |
| 245 | ||
| 246 | pu blic stati c string S erializee< T>(T data) | |
| 247 | { | |
| 248 | var ms = new Memor yStream(); | |
| 249 | var ser = new Data ContractJs onSerializ er(typeof( T)); | |
| 250 | ser.Writ eObject(ms , data); | |
| 251 | var json = ms.ToAr ray(); | |
| 252 | ms.Close (); | |
| 253 | ||
| 254 | return E ncoding.UT F8.GetStri ng(json, 0 , json.Len gth); | |
| 255 | } | |
| 256 | ||
| 257 | pu blic stati c T Deseri alize<T>(s tring json ) | |
| 258 | { | |
| 259 | var ms = new Memor yStream(En coding.UTF 8.GetBytes (json)); | |
| 260 | var ser = new Data ContractJs onSerializ er(typeof( T)); | |
| 261 | var resu lt = (T) s er.ReadObj ect(ms); | |
| 262 | ms.Close (); | |
| 263 | ||
| 264 | return r esult; | |
| 265 | } | |
| 266 | ||
| 267 | pr ivate stat ic HttpCli ent GetHtt pClient(IT racingServ ice tracin gService) | |
| 268 | { | |
| 269 | try | |
| 270 | { | |
| 271 | trac ingService .Trace("Ge tting Http Client"); | |
| 272 | var clientHand ler = new WebRequest Handler(); | |
| 273 | clie ntHandler. ClientCert ificates.A dd(GetCert KeyVault(t racingServ ice)); | |
| 274 | //cl ientHandle r.ClientCe rtificates .Add(GetLo calCert()) ; | |
| 275 | trac ingService .Trace("Cl ient Handl er Establi shed"); | |
| 276 | retu rn new Htt pClient(cl ientHandle r); | |
| 277 | } | |
| 278 | catch(We bException we) | |
| 279 | { | |
| 280 | trac ingService .Trace("Cl ient Handl er Web Exc eption"); | |
| 281 | thro w; | |
| 282 | } | |
| 283 | catch(Ex ception e) | |
| 284 | { | |
| 285 | trac ingService .Trace("Cl ient Handl er Excepti on"); | |
| 286 | thro w; | |
| 287 | } | |
| 288 | } | |
| 289 | ||
| 290 | cl ass MyClie nt : WebCl ient | |
| 291 | { | |
| 292 | protecte d override WebReques t GetWebRe quest(Uri address) | |
| 293 | { | |
| 294 | Http WebRequest request = (HttpWebR equest)bas e.GetWebRe quest(addr ess); | |
| 295 | requ est.Client Certificat es.Add(Get CertKeyVau lt(tracing Service)); | |
| 296 | retu rn request ; | |
| 297 | } | |
| 298 | } | |
| 299 | ||
| 300 | pu blic stati c X509Cert ificate2 G etLocalCer t() | |
| 301 | { | |
| 302 | var stor e = new X5 09Store(St oreName.My , StoreLoc ation.Loca lMachine); | |
| 303 | store.Op en(OpenFla gs.OpenExi stingOnly | OpenFlag s.ReadOnly ); | |
| 304 | string cer tificateSu bjectName = "CN=dws. ppms. DNS , OU=PPMS, O=VA, L=W ashington, S=DC, C=U S"; | |
| 305 | var cert = store.C ertificate s.Find(X50 9FindType. FindBySubj ectDisting uishedName , certific ateSubject Name, | |
| 306 | true ); | |
| 307 | if (cert .Count < 1 ) | |
| 308 | { | |
| 309 | thro w new Exce ption(stri ng.Format( "Could not find a va lid client certifica te with su bject {0}" , | |
| 310 | certificat eSubjectNa me)); | |
| 311 | } | |
| 312 | ||
| 313 | return c ert[0]; | |
| 314 | } | |
| 315 | ||
| 316 | pr ivate stat ic X509Cer tificate2 GetCertKey Vault(Micr osoft.Xrm. Sdk.ITraci ngService tracingSer vice) | |
| 317 | { | |
| 318 | try | |
| 319 | { | |
| 320 | trac ingService .Trace("Re trieve Cer t from Key Vault"); | |
| 321 | ||
| 322 | const stri ng appId = " REDACTED "; | |
| 323 | const stri ng secret = " REDACT E
|
|
| 324 | const stri ng tenantI d = " REDACTED "; | |
| 325 | const stri ng certUri = "https: //vanpeast ppmskv1.va ult.usgovc loudapi.ne t/certific ates/np-dw s-ppms-npr od/ REDACTED "; | |
| 326 | ||
| 327 | var token = GetToken (appId, PW , tenantId , tracingS ervice); | |
| 328 | if ( token != n ull) { tra cingServic e.Trace("T oken recei ved"); } | |
| 329 | var cert = Get Certificat eFromKeyVa ult(token. access_tok en, certUr i, tracing Service); | |
| 330 | if ( cert != nu ll) { trac ingService .Trace("Ce rt receive d"); } | |
| 331 | var privateKey = GetPriv ateKeyKeyV ault(token .access_to ken, cert. sid, traci ngService) ; | |
| 332 | if ( privateKey != null) { tracingS ervice.Tra ce("Privat e Key rece ived"); } | |
| 333 | ||
| 334 | var x509Cert = new X509C ertificate 2(privateK ey); | |
| 335 | if(x 509Cert != null) { t racingServ ice.Trace( "Cert Crea ted Succes sfully"); } | |
| 336 | else { tracing Service.Tr ace("Cert Creation F ailure"); } | |
| 337 | ||
| 338 | retu rn x509Cer t; | |
| 339 | } | |
| 340 | catch (W ebExceptio n we) | |
| 341 | { | |
| 342 | trac ingService .Trace("Ge tCertKeyVa ult WebExc eption"); | |
| 343 | retu rn null; | |
| 344 | } | |
| 345 | catch(Ex ception e) | |
| 346 | { | |
| 347 | trac ingService .Trace("Ge tCertKeyVa ult Except ion: " + e.Message. ToString() ); | |
| 348 | retu rn null; | |
| 349 | } | |
| 350 | } | |
| 351 | ||
| 352 | pr ivate stat ic TokenRe sponse Get Token(stri ng clientI d, string clientSecr et, string tenantId, Microsoft .Xrm.Sdk.I TracingSer vice traci ngService) | |
| 353 | { | |
| 354 | try | |
| 355 | { | |
| 356 | trac ingService .Trace("Ge t Token"); | |
| 357 | usin g (var htt pClient = new HttpCl ient()) | |
| 358 | { | |
| 359 | var formCo ntent = ne w FormUrlE ncodedCont ent(new[] | |
| 360 | { | |
| 361 | new KeyVal uePair<str ing, strin g>("resour ce", "http s://vault. usgovcloud api.net"), | |
| 362 | new KeyVal uePair<str ing, strin g>("client _id", clie ntId), | |
| 363 | new KeyVal uePair<str ing, strin g>("client _secret", clientSecr et), | |
| 364 | new KeyVal uePair<str ing, strin g>("grant_ type", "cl ient_crede ntials") | |
| 365 | }); | |
| 366 | ||
| 367 | var respon se = httpC lient | |
| 368 | .PostA sync("http s://login. windows.ne t/" + tena ntId + "/o auth2/toke n", formCo ntent).Get Awaiter() | |
| 369 | .GetRe sult(); | |
| 370 | ||
| 371 | return Des erialize<T okenRespon se>(respon se.Content .ReadAsStr ingAsync() .Result); | |
| 372 | } | |
| 373 | } | |
| 374 | catch(We bException we) | |
| 375 | { | |
| 376 | trac ingService .Trace("Ge tToken Web Exception" ); | |
| 377 | retu rn null; | |
| 378 | } | |
| 379 | catch(Ex ception e) | |
| 380 | { | |
| 381 | trac ingService .Trace("Ge tToken Exc eption"); | |
| 382 | retu rn null; | |
| 383 | } | |
| 384 | } | |
| 385 | ||
| 386 | pu blic stati c Certific ateRespons e GetCerti ficateFrom KeyVault(s tring toke n, string certificat eUrl, Micr osoft.Xrm. Sdk.ITraci ngService tracingSer vice) | |
| 387 | { | |
| 388 | try | |
| 389 | { | |
| 390 | usin g (var htt pClient = new HttpCl ient()) | |
| 391 | { | |
| 392 | var reques t = | |
| 393 | new Ht tpRequestM essage(Htt pMethod.Ge t, new Uri (certifica teUrl + "? api-versio n=2016-10- 01")); | |
| 394 | request.He aders.Auth orization = new Auth entication HeaderValu e("Bearer" , token); | |
| 395 | ||
| 396 | var respon se = httpC lient.Send Async(requ est).GetAw aiter().Ge tResult(); | |
| 397 | if (respon se.IsSucce ssStatusCo de) { trac ingService .Trace("Su ccessful R esponse re trieving C ertficate from KeyVa ult"); } | |
| 398 | ||
| 399 | return Des erialize<C ertificate Response>( response.C ontent.Rea dAsStringA sync().Get Awaiter(). GetResult( )); | |
| 400 | } | |
| 401 | } | |
| 402 | catch(We bException we) | |
| 403 | { | |
| 404 | trac ingService .Trace("Ge tCertifica teFromKeyV ault WebEx ception"); | |
| 405 | retu rn null; | |
| 406 | } | |
| 407 | catch(Ex ception e) | |
| 408 | { | |
| 409 | trac ingService .Trace("Ge tCertifica teFromKeyV ault Excep tion"); | |
| 410 | retu rn null; | |
| 411 | } | |
| 412 | } | |
| 413 | pu blic stati c byte[] G etPrivateK eyKeyVault (string to ken, strin g certific ateUrl, Mi crosoft.Xr m.Sdk.ITra cingServic e tracingS ervice) | |
| 414 | { | |
| 415 | try | |
| 416 | { | |
| 417 | usin g (var htt pClient = new HttpCl ient()) | |
| 418 | { | |
| 419 | var reques t = new Ht tpRequestM essage(Htt pMethod.Ge t, new Uri (certifica teUrl + "? api-versio n=2016-10- 01")); | |
| 420 | request.He aders.Auth orization = new Auth entication HeaderValu e("Bearer" , token); | |
| 421 | var respon se = httpC lient.Send Async(requ est).GetAw aiter().Ge tResult(); | |
| 422 | ||
| 423 | var privat eKey = Des erialize<P rivateKeyR esponse>(r esponse.Co ntent.Read AsStringAs ync().GetA waiter().G etResult() ); | |
| 424 | if (respon se.IsSucce ssStatusCo de) { trac ingService .Trace("Su ccessful R esponse re trieving P rivate Key "); } | |
| 425 | return Con vert.FromB ase64Strin g(privateK ey.value); | |
| 426 | } | |
| 427 | } | |
| 428 | catch(We bException we) | |
| 429 | { | |
| 430 | trac ingService .Trace("Ge tPrivateKe yKeyVault WebExcepti on"); | |
| 431 | retu rn null; | |
| 432 | } | |
| 433 | catch(Ex ception e) | |
| 434 | { | |
| 435 | trac ingService .Trace("Ge tPrivateKe yKeyVault Exception" ); | |
| 436 | retu rn null; | |
| 437 | } | |
| 438 | } | |
| 439 | } | |
| 440 | ||
| 441 | public class Tok enResponse | |
| 442 | { | |
| 443 | pu blic strin g token_ty pe { get; set; } | |
| 444 | pu blic strin g expires_ in { get; set; } | |
| 445 | pu blic strin g ext_expi res_in { g et; set; } | |
| 446 | pu blic strin g expires_ on { get; set; } | |
| 447 | pu blic strin g not_befo re { get; set; } | |
| 448 | pu blic strin g resource { get; se t; } | |
| 449 | pu blic strin g access_t oken { get ; set; } | |
| 450 | } | |
| 451 | ||
| 452 | public class Cer tificateRe sponse | |
| 453 | { | |
| 454 | pu blic strin g id { get ; set; } | |
| 455 | pu blic strin g kid { ge t; set; } | |
| 456 | pu blic strin g sid { ge t; set; } | |
| 457 | pu blic strin g x5t { ge t; set; } | |
| 458 | pu blic strin g cer { ge t; set; } | |
| 459 | } | |
| 460 | public class Pri vateKeyRes ponse | |
| 461 | { | |
| 462 | pu blic strin g value { get; set; } | |
| 463 | } | |
| 464 | ||
| 465 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.