AadAuthenticationFactory.psm1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 |
#region Public commands function Get-AadAccount { <# .SYNOPSIS Returns account(s) from AAD authentication factory cache .DESCRIPTION For supported factory types, command returns either account(s) that match provided user account, or all accounts available in the cche. For unsupported factories (those working with Managed Identities) does not return anything .OUTPUTS One or more accounts found in factory cache .NOTES Command uses -match operator to match value of UserName parameter with usernames of accounts in factory's cache .EXAMPLE $factory = New-AadAuthenticationFactory -TenantId mydomain.com -RequiredScopes @('https://eventgrid.azure.net/.default') -AuthMode Interactive Get-AadAccount -Factory $factory -All Description ----------- Returns all accounts from factory cache .EXAMPLE New-AadAuthenticationFactory -TenantId mydomain.com -RequiredScopes @('https://eventgrid.azure.net/.default') -AuthMode Interactive Get-AadAccount -UserName John Description ----------- Returns all accounts from factory cache that match pattern 'John'. #> [CmdletBinding()] param ( [Parameter(ValueFromPipeline, ParameterSetName = 'SpecificAcount')] #User name to get account information for #If not specified, all accounts cached in factory are returned [string]$UserName, [Parameter(ParameterSetName = 'All')] #tells the command to return all accounts available [switch]$All, #AAD authentication factory created via New-AadAuthenticationFactory $Factory = $script:AadLastCreatedFactory ) begin { [System.Threading.CancellationTokenSource]$cts = new-object System.Threading.CancellationTokenSource([timespan]::FromSeconds(180)) } process { if($factory -is [Microsoft.Identity.Client.PublicClientApplication]) { if([string]::IsNullOrEmpty($Factory.B2CPolicy)) { $allAccounts = $Factory.GetAccountsAsync() | AwaitTask -CancellationTokenSource $cts } else { $allAccounts = $Factory.GetAccountsAsync($Factory.B2CPolicy) | AwaitTask -CancellationTokenSource $cts } switch($PSCmdlet.ParameterSetName) { 'All' { $allAccounts break; } 'SpecificAcount' { if(-not [string]::IsNullOrEmpty($UserName)) { $allAccounts | Where-Object{$_.UserName -match $Username} } else { if($allAccounts.Count -gt 0) { $allAccounts[0] } } break; } } } } end { if($null -ne $cts) { $cts.Dispose() } } } function Get-AadDefaultClientId { <# .SYNOPSIS Returns default AAD client ID used by module, which is client id for Azure Powershell .DESCRIPTION Returns default AAD client ID used by module, which is client id for Azure Powershell .OUTPUTS Default client id used by module #> [CmdletBinding()] param ( ) process { $module = $MyInvocation.MyCommand.Module $Module.PrivateData.Configuration.DefaultClientId } } function Get-AadToken { <# .SYNOPSIS Retrieves AAD token according to configuration of authentication factory .DESCRIPTION Retrieves AAD token according to configuration of authentication factory .OUTPUTS Authentication result from AAD with tokens and other information, or hashtable with Authorization header .EXAMPLE $factory = New-AadAuthenticationFactory -TenantId mydomain.com -RequiredScopes @('https://eventgrid.azure.net/.default') -AuthMode Interactive $token = $factory | Get-AadToken Description ----------- Command creates authentication factory and retrieves AAD token from it, authenticating user via web view or browser .EXAMPLE $cosmosDbAccountName = 'myCosmosDBAcct $factory = New-AadAuthenticationFactory -DefaultScopes @("https://$cosmosDbAccountName`.documents.azure.com/.default") -UseManagedIdentity $token = $factory | Get-AadToken Description ----------- Command creates authentication factory and retrieves AAD token for access data plane of cosmos DB aaccount. For details on CosmosDB RBAC access, see https://learn.microsoft.com/en-us/azure/cosmos-db/how-to-setup-rbac .EXAMPLE $factory = New-AadAuthenticationFactory -TenantId mydomain.com -AuthMode WIA $token = $factory | Get-AadToken -Scopes @('https://eventgrid.azure.net/.default') Description ----------- Command creates authentication factory without default scopes and retrieves AAD token for access to event grid, specifying scopes when asking for token .EXAMPLE New-AadAuthenticationFactory -TenantId mydomain.com -RequiredScopes @('api://mycompany.com/myapi/.default') -AuthMode WIA $headers = Get-AadToken -AsHashtable Invoke-RestMethod -Uri "https://myapi.mycomany.com/items" -Headers $headers Description ----------- Command shows how to get token as hashtable containing properly formatted Authorization header and use it to authenticate call method on REST API #> [CmdletBinding()] param ( [Parameter()] [Alias("RequiredScopes")] #Scopes to be returned in the token. #If not specified, returns token with default scopes provided when creating the factory [string[]]$Scopes = $null, [Parameter()] #User name hint for authentication process [string]$UserName, [Parameter()] #Access token for user #Used to identify user in on-behalf-of flows [string]$UserToken, #When specified, hashtable with Authorization header is returned instead of token #This is shortcut to use when just need to have token for authorization header to call REST API (e.g. via Invoke-RestMethod) #When not specified, returns authentication result with tokens and other metadata [switch]$AsHashTable, #Asks runtime to avoid token cache and get fresh token from AAD [switch]$forceRefresh, [Parameter(ValueFromPipeline)] #AAD authentication factory created via New-AadAuthenticationFactory $Factory = $script:AadLastCreatedFactory ) begin { Write-Verbose "Initializing" [System.Threading.CancellationTokenSource]$cts = new-object System.Threading.CancellationTokenSource([timespan]::FromSeconds(180)) } process { if($null -eq $Factory) { Write-Error "Please pass valid instance of AAD Authentication Factory" return } if($null -eq $Scopes) { $scopes = $factory.DefaultScopes if($null -eq $Scopes) { throw (new-object System.ArgumentException("No scopes specified")) } } if([string]::IsNullOrWhiteSpace($UserName)) { $UserName = $factory.DefaultUserName } if(-not [string]::IsNullOrEmpty($UserToken)) { if($Factory.FlowType -ne [AuthenticationFlow]::ConfidentialClient) { throw (new-object System.ArgumentException("Unsupported authentication flow for on-behalf-of: $($Factory.FlowType)")) } $assertion = new-object Microsoft.Identity.Client.UserAssertion($UserToken) Write-Verbose "Getting token with assertion $($assertion.AssertionType) $($assertion.Assertion)" $task = $Factory.AcquireTokenOnBehalfOf($Scopes, $assertion).ExecuteAsync($cts.Token) } else { Write-Verbose "Getting account from cache" $account = Get-AadAccount -UserName $UserName -Factory $Factory switch($Factory.FlowType) { ([AuthenticationFlow]::PublicClient) { try { Write-Verbose "Getting token for $($account.Username)" $task = $factory.AcquireTokenSilent($scopes,$account).WithForceRefresh($forceRefresh).ExecuteAsync($cts.Token) $rslt = $task | AwaitTask -CancellationTokenSource $cts } catch [Microsoft.Identity.Client.MsalUiRequiredException] { Write-Verbose "Getting token interactively" $task = $factory.AcquireTokenInteractive($Scopes).ExecuteAsync($cts.Token) $rslt = $task | AwaitTask -CancellationTokenSource $cts } break; } ([AuthenticationFlow]::PublicClientWithWia) { if($null -ne $Account) { Write-Verbose "Getting token for $($account.Username)" $task = $factory.AcquireTokenSilent($Scopes, $account).WithForceRefresh($forceRefresh).ExecuteAsync() $rslt = $task | AwaitTask -CancellationTokenSource $cts } else { Write-Verbose "Getting token with explicit auth" $task = $factory.AcquireTokenByIntegratedWindowsAuth($Scopes).WithUserName($UserName).ExecuteAsync($cts.Token) $rslt = $task | AwaitTask -CancellationTokenSource $cts #let the app throw to caller when UI required as the purpose here is to stay silent } break; } ([AuthenticationFlow]::PublicClientWithWam) { if($null -eq $Account -and [string]::IsNullOrEmpty($userName)) { Write-Verbose "Getting token for OperatingSystemAccount" $account = [Microsoft.Identity.Client.PublicClientApplication]::OperatingSystemAccount } try { Write-Verbose "Getting token silently" $task = $factory.AcquireTokenSilent($scopes,$account).WithForceRefresh($forceRefresh).ExecuteAsync($cts.Token) $rslt = $task | AwaitTask -CancellationTokenSource $cts } catch [Microsoft.Identity.Client.MsalUiRequiredException] { $windowHandle = [ParentWindowHelper]::GetConsoleOrTerminalWindow() $builder = $factory.AcquireTokenInteractive($Scopes) if(-not [string]::IsNullOrEmpty($UserName)) { Write-Verbose "Falling back to UI auth with parent window hadle: $windowHandle and login hint: $userName" $builder = $builder.WithLoginHint($userName) } else { Write-Verbose "Falling back to UI auth with parent window hadle: $windowHandle and account: $($account.userName)" $builder = $builder.WithAccount($account) } $task = $builder.WithParentActivityOrWindow($windowHandle).ExecuteAsync($cts.Token) $rslt = $task | AwaitTask -CancellationTokenSource $cts } break; } ([AuthenticationFlow]::PublicClientWithDeviceCode) { try { Write-Verbose "Getting token for $($account.Username)" $task = $factory.AcquireTokenSilent($scopes,$account).WithForceRefresh($forceRefresh).ExecuteAsync($cts.Token) $rslt = $task | AwaitTask -CancellationTokenSource $cts } catch [Microsoft.Identity.Client.MsalUiRequiredException] { Write-Verbose "Getting token with device code" $task = $factory.AcquireTokenWithDeviceCode($Scopes,[DeviceCodeHandler]::Get()).ExecuteAsync($cts.Token) $rslt = $task | AwaitTask -CancellationTokenSource $cts } break; } ([AuthenticationFlow]::ResourceOwnerPassword) { try { $creds = $factory.ResourceOwnerCredential if($forceRefresh) { Write-Verbose "Refreshing token with explicit credentials" $task = $factory.AcquireTokenByUsernamePassword($Scopes, $creds.UserName, $creds.GetNetworkCredential().Password).ExecuteAsync() $rslt = $task | AwaitTask -CancellationTokenSource $cts } else { Write-Verbose "Getting token silently" $task = $factory.AcquireTokenSilent($scopes,$account).ExecuteAsync($cts.Token) $rslt = $task | AwaitTask -CancellationTokenSource $cts } } catch [Microsoft.Identity.Client.MsalUiRequiredException] { Write-Verbose "Getting token with credentials" $task = $factory.AcquireTokenByUsernamePassword($Scopes, $creds.UserName, $creds.GetNetworkCredential().Password).ExecuteAsync() $rslt = $task | AwaitTask -CancellationTokenSource $cts } break; } ([AuthenticationFlow]::ConfidentialClient) { Write-Verbose "Getting token for confidentioal client" $task = $factory.AcquireTokenForClient($scopes).WithForceRefresh($forceRefresh).ExecuteAsync($cts.Token) $rslt = $task | AwaitTask -CancellationTokenSource $cts break } ([AuthenticationFlow]::ManagedIdentity) { Write-Verbose "Getting token for system-assigned MSI" $task = $Factory.AcquireTokenForManagedIdentity($scopes).WithForceRefresh($forceRefresh).ExecuteAsync() $rslt = $task | AwaitTask -CancellationTokenSource $cts break } ([AuthenticationFlow]::UserAssignedIdentity) { Write-Verbose "Getting token for user-assigned MSI" $task = $Factory.AcquireTokenForManagedIdentity($scopes).WithForceRefresh($forceRefresh).ExecuteAsync() $rslt = $task | AwaitTask -CancellationTokenSource $cts break } default { throw (new-object System.ArgumentException("Unsupported authentication flow: $_")) } } } if($AsHashTable) { Write-Verbose 'Converting token to authorization header' @{ 'Authorization' = $rslt.CreateAuthorizationHeader() } } else { $rslt } } end { if($null -ne $cts) { Write-Verbose "Disposing resources" $cts.Dispose() } } } function New-AadAuthenticationFactory { <# .SYNOPSIS Creates authentication factory with provided parameters for Public or Confidential client flows .DESCRIPTION Creates authentication factory with provided parameters for Public or Confidential client flows Authentication uses by default well-know clientId of Azure Powershell, but can accept clientId of app registered in your own tenant. .OUTPUTS AadAuthenticationFactory object .EXAMPLE New-AadAuthenticationFactory -TenantId mydomain.com -RequiredScopes @('https://my-db.documents.azure.com/.default') -AuthMode Interactive Description ----------- This command returns AAD authentication factory for Public client auth flow with well-known clientId for Azure PowerShell and interactive authentication for getting tokens for CosmosDB account .EXAMPLE $proxy=new-object System.Net.WebProxy('http://myproxy.mycompany.com:8080') $proxy.BypassProxyOnLocal=$true $factory = New-AadAuthenticationFactory -TenantId mydomain.com -RequiredScopes @('https://eventgrid.azure.net/.default') -AuthMode deviceCode -Proxy $proxy $token = $factory | Get-AadToken Description ----------- Command works in on prem environment where access to internet is available via proxy. Command authenticates user with device code flow. .EXAMPLE $creds = Get-Credential New-AadAuthenticationFactory -TenantId 'mytenant.com' -ResourceOwnerCredential $creds -RequiredScopes 'https://vault.azure.net/.default' $vaultToken = Get-AadToken Description ----------- Command collects credentials of cloud-only account and authenticates with Resource Owner Password flow to get access token for Azure KeyVault. Get-AadToken command uses implicit factory cached from last call of New-AadAuthenticationFactory #> param ( [Parameter()] [Alias("RequiredScopes")] [string[]] #Scopes to ask token for $DefaultScopes, [Parameter(Mandatory,ParameterSetName = 'ConfidentialClientWithSecret')] [Parameter(Mandatory,ParameterSetName = 'ConfidentialClientWithCertificate')] [Parameter(Mandatory,ParameterSetName = 'PublicClient')] [Parameter(Mandatory,ParameterSetName = 'ResourceOwnerPasssword')] [string] #Id of tenant where to autenticate the user. Can be tenant id, or any registerd DNS domain #You can also use AAD placeholder: organizations, common, consumers $TenantId, [Parameter()] [string] #ClientId of application that gets token #Default: well-known clientId for Azure PowerShell $ClientId = (Get-AadDefaultClientId), [Parameter()] [Uri] #RedirectUri for the client #Default: default MSAL redirect Uri $RedirectUri, [Parameter(ParameterSetName = 'ConfidentialClientWithSecret')] [string] #Client secret for ClientID #Used to get access as application rather than as calling user $ClientSecret, [Parameter(ParameterSetName = 'ResourceOwnerPasssword')] [pscredential] #Resource Owner username and password for public client ROPC flow #Used to get access as user specified by credential #Note: Does not work for federated authentication $ResourceOwnerCredential, [Parameter(ParameterSetName = 'ConfidentialClientWithCertificate')] [System.Security.Cryptography.X509Certificates.X509Certificate2] #Authentication certificate for ClientID #Used to get access as application rather than as calling user $X509Certificate, [Parameter(ParameterSetName = 'ConfidentialClientWithSecret')] [Parameter(ParameterSetName = 'ConfidentialClientWithCertificate')] [Parameter(ParameterSetName = 'PublicClient')] [Parameter(ParameterSetName = 'ResourceOwnerPasssword')] [string] #AAD auth endpoint #Default: endpoint for public cloud $LoginApi = 'https://login.microsoftonline.com', [Parameter(ParameterSetName = 'ConfidentialClientWithSecret')] [Parameter(ParameterSetName = 'ConfidentialClientWithCertificate')] [Parameter(ParameterSetName = 'PublicClient')] [Parameter(ParameterSetName = 'ResourceOwnerPasssword')] [string] #Name of the B2C policy to use for login #Specifying this parameter means that you want to use B2B logig and expects you to provide B2C tenant name in tenant ID #Default: endpoint for public cloud $B2CPolicy, [Parameter(Mandatory, ParameterSetName = 'PublicClient')] [ValidateSet('Interactive', 'DeviceCode', 'WIA', 'WAM')] [string] #How to authenticate client - via web view, via device code flow, or via Windows Integrated Auth #Used in public client flows $AuthMode, [Parameter(ParameterSetName = 'PublicClient')] [Alias("UserNameHint")] [string] #Username hint for authentication UI #Optional $DefaultUserName, [Parameter(ParameterSetName = 'MSI')] [Switch] #tries to get parameters from environment and token from internal endpoint provided by Azure MSI support $UseManagedIdentity, [Parameter()] [System.Net.WebProxy] #Web proxy configuration #Optional $proxy = $null ) process { $module = $MyInvocation.MyCommand.Module $moduleName = $module.Name $moduleVersion = $module.Version if($null -ne $Module.privatedata.psdata.Prerelease) {$moduleVersion = "$moduleVersion`-$($Module.privatedata.psdata.Prerelease)"} $useDefaultCredentials = $false if([string]::IsNullOrEmpty($B2CPolicy)) { $AuthorityUri = "$LoginApi/$TenantId" } else { $AuthorityUri = "$LoginApi/tfp/$TenantId/$B2CPolicy" } #setup of common options switch($PSCmdlet.ParameterSetName) { {$_ -in 'ConfidentialClientWithSecret','ConfidentialClientWithCertificate'} { $opts = new-object Microsoft.Identity.Client.ConfidentialClientApplicationOptions $opts.ClientId = $clientId $opts.clientName = $moduleName $opts.ClientVersion = $moduleVersion if(-not [string]::IsNullOrEmpty($RedirectUri)) { $opts.RedirectUri = $RedirectUri } $builder = [Microsoft.Identity.Client.ConfidentialClientApplicationBuilder]::CreateWithApplicationOptions($opts) if($_ -eq 'ConfidentialClientWithSecret') { $builder = $builder.WithClientSecret($ClientSecret) } else { $builder = $builder.WithCertificate($X509Certificate) } if([string]::IsNullOrEmpty($B2CPolicy)) { $builder = $builder.WithAuthority($AuthorityUri) } else { $builder = $builder.WithB2CAuthority($authorityUri) } $flowType = [AuthenticationFlow]::ConfidentialClient break; } {$_ -in 'PublicClient','ResourceOwnerPasssword'} { $opts = new-object Microsoft.Identity.Client.PublicClientApplicationOptions $opts.ClientId = $clientId $opts.clientName = $moduleName $opts.ClientVersion = $moduleVersion $builder = [Microsoft.Identity.Client.PublicClientApplicationBuilder]::CreateWithApplicationOptions($opts) if([string]::IsNullOrEmpty($B2CPolicy)) { $builder = $builder.WithAuthority($AuthorityUri) } else { $builder = $builder.WithB2CAuthority($authorityUri) } if(-not [string]::IsNullOrEmpty($RedirectUri)) { $builder = $builder.WithRedirectUri($RedirectUri) } else { $builder = $builder.WithDefaultRedirectUri() } if($_ -eq 'ResourceOwnerPasssword') { $flowType = [AuthenticationFlow]::ResourceOwnerPassword } else { switch ($AuthMode) { 'WIA' { if([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform([System.Runtime.InteropServices.OSPlatform]::Windows)) { $flowType = [AuthenticationFlow]::PublicClientWithWia $useDefaultCredentials = $true } else { throw New-Object System.PlatformNotSupportedException("WIA is only supported on Windows platform") } break } 'DeviceCode' { $flowType = [AuthenticationFlow]::PublicClientWithDeviceCode break } 'WAM' { if([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform([System.Runtime.InteropServices.OSPlatform]::Windows)) { $flowType = [AuthenticationFlow]::PublicClientWithWam $opts = new-object Microsoft.Identity.Client.BrokerOptions('Windows') $builder = [Microsoft.Identity.Client.Broker.BrokerExtension]::WithBroker($builder,$opts) } else { throw New-Object System.PlatformNotSupportedException("WAM is only supported on Windows platform") } break } Default { $flowType = [AuthenticationFlow]::PublicClient break } } } break; } 'MSI' { if($clientId -eq (Get-AadDefaultClientId) -or [string]::IsNullOrEmpty($clientId)) { $managedIdentityId = [Microsoft.Identity.Client.AppConfig.ManagedIdentityId]::SystemAssigned $flowType = [AuthenticationFlow]::ManagedIdentity } else { $managedIdentityId = [Microsoft.Identity.Client.AppConfig.ManagedIdentityId]::WithUserAssignedClientId($clientId) $flowType = [AuthenticationFlow]::UserAssignedIdentity } $builder = [Microsoft.Identity.Client.ManagedIdentityApplicationBuilder]::Create($managedIdentityId) break; } default { throw (new-object System.ArgumentException("Unsupported flow type: $_")) } } #crate factory and add to builder $httpFactory = [GcMsalHttpClientFactory]::Create($proxy,$ModuleVersion,$useDefaultCredentials) $builder = $builder.WithHttpClientFactory($httpFactory) #build the app and add processing info $script:AadLastCreatedFactory = $builder.Build() ` | Add-Member -MemberType NoteProperty -Name FlowType -Value $flowType -PassThru ` | Add-Member -MemberType NoteProperty -Name DefaultScopes -Value $DefaultScopes -PassThru ` | Add-Member -MemberType NoteProperty -Name DefaultUserName -Value $DefaultUserName -PassThru ` | Add-Member -MemberType NoteProperty -Name ResourceOwnerCredential -Value $ResourceOwnerCredential -PassThru ` | Add-Member -MemberType NoteProperty -Name B2CPolicy -Value $B2CPolicy -PassThru #Give the factory common type name for formatting $script:AadLastCreatedFactory.psobject.typenames.Insert(0,'GreyCorbel.Identity.Authentication.AadAuthenticationFactory') $script:AadLastCreatedFactory } } function Test-AadToken { <# .SYNOPSIS Parses and validates AAD-issued token .DESCRIPTION Parses provided IdToken or AccessToken and checks for its validity. Note that some tokens may not be properly validated - this is in case then 'nonce' field present and set in the haeder. AAD issues such tokens for Graph API and nonce is taken into consideration when validating the token. See discussion at https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/issues/609 for more details. .OUTPUTS Parsed token and information about its validity .EXAMPLE $factory = New-AadAuthenticationFactory -TenantId mydomain.com -RequiredScopes @('https://eventgrid.azure.net/.default') -AuthMode Interactive $token = $factory | Get-AadToken $token.idToken | Test-AadToken | fl Description ----------- Command creates authentication factory, asks it to issue token for EventGrid and parses IdToken and validates it .EXAMPLE New-AadAuthenticationFactory -TenantId mydomain.com -DefaultScopes @('https://graph.microsoft.com/.default') -AuthMode Interactive Get-AadToken | Test-AadToken -PayloadOnly Description ----------- Command creates authentication factory, asks it to issue token for MS Graph and parses AccessToken (this is token to use when passing complete response from Get-AadToken), validates it and shows claims contained #> [CmdletBinding()] param ( [Parameter(Mandatory,ValueFromPipeline)] [object] #IdToken or AccessToken field from token returned by Get-AadToken #or complete result of Get-AadToken - in such case, AccessToken is examined $Token, [switch] $PayloadOnly ) process { if($token -is [Microsoft.Identity.Client.AuthenticationResult]) { if($null -ne $token.AccessToken) { Write-Verbose 'Using AccessToken from provided token' $Token = $Token.AccessToken } else { if($null -ne $token.IdToken) { Write-Verbose 'Using IdToken from provided token' $Token = $Token.IdToken } else { Write-Error 'Invalid format of provided token' return } } } else { if($token -is [System.Collections.Hashtable]) { if($null -ne $token['Authorization']) { Write-Verbose 'Using AccessToken from provided hashtable' $token = $token['Authorization'].Replace('Bearer ','') } else { Write-Error 'Provided hashtable does not contain Authorization key' } } else { Write-Verbose 'Using provided plaintext token' } } $parts = $token.split('.') if($parts.Length -ne 3) { Write-Error 'Invalid format of provided token' return } Write-Verbose "Parsing the token" $result = [PSCustomObject]@{ Header = [System.Text.Encoding]::UTF8.GetString([Convert]::FromBase64String((Base64UrlDecode -Data $parts[0]))) | ConvertFrom-Json Payload = [System.Text.Encoding]::UTF8.GetString([Convert]::FromBase64String((Base64UrlDecode -Data $parts[1]))) | ConvertFrom-Json IsValid = $false } #validate the result using published keys if($null -eq $result.Payload.tfp) { #AAD token Write-Verbose "It's standard AAD token" $endpoint = $result.Payload.iss.Replace('/v2.0','') $keysEndpoint = "$($endpoint)/discovery/v2.0/keys" } else { #AAD B2C token Write-Verbose "It's B2C token" $endpoint = $result.Payload.iss.Replace('/v2.0/','') $keysEndpoint = "$endpoint/$($result.Payload.tfp)/discovery/v2.0/keys" } Write-Verbose "Getting signing keys from $keysEndpoint" $signingKeys = Invoke-RestMethod -Method Get -Uri $keysEndpoint Write-Verbose "Received $($signingKeys.keys.count) signing keys:" Write-Verbose ($signingKeys | ConvertTo-Json -Depth 9) $key = $signingKeys.keys | Where-object{$_.kid -eq $result.Header.kid} if($null -eq $key) { Write-Warning "Could not find signing key with id = $($result.Header.kid) on endpoint $keysEndpoint" return $result } Write-Verbose "Using key with kid: $($key.kid)" $rsa = $null if($null -ne $key.e -and $null -ne $key.n) { Write-Verbose "Getting public key from modulus $($key.n) and exponent $($key.e)" $exponent = Base64UrlDecode -data $key.e $exponent = [convert]::FromBase64String($exponent) $modulus = Base64UrlDecode -data $key.n $modulus = [convert]::FromBase64String($modulus) $rsa = new-object System.Security.Cryptography.RSACryptoServiceProvider $params = new-object System.Security.Cryptography.RSAParameters $params.Exponent = $exponent $params.Modulus = $modulus $rsa.ImportParameters($params) } else { if($null -ne $key.x5c) { Write-Verbose "Getting public key from x5c: $($key.x5c)" $cert = new-object System.Security.Cryptography.X509Certificates.X509Certificate2(,[Convert]::FromBase64String($key.x5c[0])) $rsa = $cert.PublicKey.Key } } if($null -eq $rsa) { Write-Warning "Could not validate the token as both x5c and n/e information is missing" return $result } Write-Verbose "Creating payload to validate" $payload = "$($parts[0]).$($parts[1])" $dataToVerify = [System.Text.Encoding]::UTF8.GetBytes($payload) $sig = Base64UrlDecode -Data $parts[2] $signature = [Convert]::FromBase64String($sig) switch($result.Header.alg) { 'RS384' { $hash = [System.Security.Cryptography.HashAlgorithmName]::SHA384 break; } 'RS512' { $hash = [System.Security.Cryptography.HashAlgorithmName]::SHA512 break; } default { $hash = [System.Security.Cryptography.HashAlgorithmName]::SHA256 break; } } $padding = [System.Security.Cryptography.RSASignaturePadding]::Pkcs1 Write-Verbose "Validating payload" $result.IsValid = $rsa.VerifyData($dataToVerify,$signature,$hash,$Padding) if($null -ne $cert) {$cert.Dispose()} if($null -ne $result.Header.nonce) { Write-Verbose "Header contains nonce, so token may not be properly validated. See https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/issues/609" } $result.psobject.typenames.Insert(0,'GreyCorbel.Identity.Authentication.TokenValidationResult') if($PayloadOnly) { $result.Payload } else { $result } } } #endregion Public commands #region Internal commands enum AuthenticationFlow { #Public client with browser based auth PublicClient #Public client with console based auth PublicClientWithDeviceCode #Public client with Windows Integrated auth PublicClientWithWia #Public client with Windows Authentication Broker PublicClientWithWam #Confidential client with client secret or certificate ConfidentialClient #Confidential client with System-assigned Managed identity or Arc-enabled server ManagedIdentity #Confidential client with User-assigned Managed identity UserAssignedIdentity #Unattended Resource Owner auth with username and password ResourceOwnerPassword } function AwaitTask { param ( [Parameter(ValueFromPipeline, Mandatory)] $task, [Parameter(Mandatory)] [System.Threading.CancellationTokenSource]$CancellationTokenSource ) process { try { $errorHappened = $false while (-not $task.AsyncWaitHandle.WaitOne(200)) { } $rslt = $task.GetAwaiter().GetResult() $rslt } catch [System.OperationCanceledException]{ $errorHappened = $true Write-Warning 'Authentication process has timed out' } catch { $errorHappened = $true throw $_.Exception } finally { if(-not $errorHappened -and $null -eq $rslt) { #we do not have result and did not went thru Catch block --> likely Ctrl+Break scenario #let`s cancel authentication in the factory $CancellationTokenSource.Cancel() Write-Verbose 'Authentication canceled by Ctrl+Break' } } } } function Base64UrlDecode { param ( [Parameter(Mandatory,ValueFromPipeline)] [string]$Data ) process { $result = $Data $result = $result.Replace('-','+').Replace('_','/') switch($result.Length % 4) { 0 {break;} 2 {$result = "$result=="; break} 3 {$result = "$result="; break;} default {throw "Invalid data format"} } $result } } function Init { param() process { $referencedAssemblies = @('System.Net.Http') #load platform specific switch($PSEdition) { 'Core' { $referencedAssemblies+="System.Net.Primitives" $referencedAssemblies+="System.Net.WebProxy" $referencedAssemblies+="System.Console" try { $existingType = [Microsoft.Identity.Client.PublicClientApplication] #compiling http factory against version of preloaded package $referencedAssemblies+=$existingType.Assembly.Location } catch { Add-Type -Path ([System.IO.Path]::Combine([string[]]($PSScriptRoot,'Shared','net6.0','Microsoft.IdentityModel.Abstractions.dll'))) Add-Type -Path ([System.IO.Path]::Combine([string[]]($PSScriptRoot,'Shared','net6.0','Microsoft.Identity.Client.dll'))) #compiling http factory against our version $referencedAssemblies+=[System.IO.Path]::Combine([string[]]($PSScriptRoot,'Shared','net6.0','Microsoft.Identity.Client.dll')) } #on Windows, load WAM broker if($null -eq ('Microsoft.Identity.Client.Broker.BrokerExtension' -as [type])) { Add-Type -Path ([System.IO.Path]::Combine([string[]]($PSScriptRoot,'Shared','netstandard2.0','Microsoft.Identity.Client.Broker.dll'))) if([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform([System.Runtime.InteropServices.OSPlatform]::Windows)) { switch($env:PROCESSOR_ARCHITECTURE) { 'AMD64' {$runtimePath = [System.IO.Path]::Combine([string[]]($PSScriptRoot,'Runtimes','win-x64','native')); break;} 'ARM64' {$runtimePath = [System.IO.Path]::Combine([string[]]($PSScriptRoot,'Runtimes','win-arm64','native')); break;} 'X86' {$runtimePath = [System.IO.Path]::Combine([string[]]($PSScriptRoot,'Runtimes','win-x86','native')); break;} } if(-not [string]::IsNullOrEmpty($runtimePath)) { $env:Path = "$($env:Path);$runtimePath" } } } break; } 'Desktop' { try { $existingType = [Microsoft.Identity.Client.PublicClientApplication] #compiling http factory against version of preloaded package $referencedAssemblies+=$existingType.Assembly.Location } catch { Add-Type -Path ([System.IO.Path]::Combine([string[]]($PSScriptRoot,'Shared','net461','Microsoft.IdentityModel.Abstractions.dll'))) Add-Type -Path ([System.IO.Path]::Combine([string[]]($PSScriptRoot,'Shared','net461','Microsoft.Identity.Client.dll'))) $referencedAssemblies+=[System.IO.Path]::Combine([string[]]($PSScriptRoot,'Shared','net461','Microsoft.Identity.Client.dll')) } #on Windows, load WAM broker if($null -eq ('Microsoft.Identity.Client.Broker.BrokerExtension' -as [type])) { if([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform([System.Runtime.InteropServices.OSPlatform]::Windows)) { Add-Type -Path ([System.IO.Path]::Combine([string[]]($PSScriptRoot,'Shared','net461','Microsoft.Identity.Client.Broker.dll'))) #need to add path to native runtime supporting the broker switch($env:PROCESSOR_ARCHITECTURE) { 'AMD64' {$runtimePath = [System.IO.Path]::Combine([string[]]($PSScriptRoot,'Runtimes','win-x64','native')); break;} 'ARM64' {$runtimePath = [System.IO.Path]::Combine([string[]]($PSScriptRoot,'Runtimes','win-arm64','native')); break;} 'X86' {$runtimePath = [System.IO.Path]::Combine([string[]]($PSScriptRoot,'Runtimes','win-x86','native')); break;} } if(-not [string]::IsNullOrEmpty($runtimePath)) { $env:Path = "$($env:Path);$runtimePath" } } } #on desktop, this one is not pre-loaded Add-Type -Assembly System.Net.Http #for desktop, we do not use separate app domain (will add if needed) break; } } [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 #check if we need to load or already loaded if($null -eq ('GcMsalHttpClientFactory' -as [type])) { $httpFactoryDefinition = Get-Content "$PSScriptRoot\Helpers\GcMsalHttpClientFactory.cs" -Raw Add-Type -TypeDefinition $httpFactoryDefinition -ReferencedAssemblies $referencedAssemblies -WarningAction SilentlyContinue -IgnoreWarnings } if($null -eq ('DeviceCodeHandler' -as [type])) { #check if we need to load or already loaded $deviceCodeHandlerDefinition = Get-Content "$PSScriptRoot\Helpers\DeviceCodeHandler.cs" -Raw Add-Type -TypeDefinition $deviceCodeHandlerDefinition -ReferencedAssemblies $referencedAssemblies -WarningAction SilentlyContinue -IgnoreWarnings } if($null -eq ('ParentWindowHelper' -as [type])) { #check if we need to load or already loaded $parentWindowHelperDefinition = Get-Content "$PSScriptRoot\Helpers\ParentWindowHelper.cs" -Raw Add-Type -TypeDefinition $parentWindowHelperDefinition -ReferencedAssemblies $referencedAssemblies -WarningAction SilentlyContinue -IgnoreWarnings } } } #endregion Internal commands #region Module initialization Init #endregion Module initialization # SIG # Begin signature block # MIInDwYJKoZIhvcNAQcCoIInADCCJvwCAQExDzANBglghkgBZQMEAgEFADB5Bgor # BgEEAYI3AgEEoGswaTA0BgorBgEEAYI3AgEeMCYCAwEAAAQQH8w7YFlLCE63JNLG # KX7zUQIBAAIBAAIBAAIBAAIBADAxMA0GCWCGSAFlAwQCAQUABCAjGdcNdnNf9Od/ # 8VJMBV4Erg/lMLr1Ds+UXwcJpQOtEaCCIJIwggWNMII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