1313using System . Net . Http . Headers ;
1414using System . Text ;
1515using System . Threading . Tasks ;
16+ using System . Windows . Forms ;
1617
1718namespace ConverterLibrary
1819{
@@ -36,10 +37,15 @@ public class Converter : PSCmdlet
3637 public string SubscriptionId ;
3738 [ Parameter (
3839 Mandatory = false ,
39- HelpMessage = "Authorization Bearer Token" ,
40- ValueFromPipeline = true
40+ HelpMessage = "Authorization Bearer Token"
4141 ) ]
4242 public string Token = "" ;
43+ [ Parameter (
44+ Mandatory = false ,
45+ HelpMessage = "Piped input from armclient" ,
46+ ValueFromPipeline = true
47+ ) ]
48+ public string ClaimsDump ;
4349 private DeploymentTemplate template ;
4450 private JObject workflowTemplateReference ;
4551
@@ -56,16 +62,31 @@ public Converter(string token) : this()
5662
5763 protected override void ProcessRecord ( )
5864 {
59- if ( String . IsNullOrEmpty ( Token ) )
65+ if ( ClaimsDump == null )
6066 {
61- AuthenticationContext ac = new AuthenticationContext ( Constants . AuthString , true ) ;
62- var ar = ac . AcquireToken ( Constants . ResourceUrl , Constants . ClientId , new Uri ( Constants . RedirectUrl ) , PromptBehavior . Always ) ;
67+ WriteVerbose ( "No armclient token piped through. Attempting to authenticate" ) ;
68+ if ( String . IsNullOrEmpty ( Token ) )
69+ {
70+ AuthenticationContext ac = new AuthenticationContext ( Constants . AuthString , true ) ;
71+ var ar = ac . AcquireToken ( Constants . ResourceUrl , Constants . ClientId , new Uri ( Constants . RedirectUrl ) , PromptBehavior . Always ) ;
6372
6473
65- Token = ar . AccessToken ;
74+ Token = ar . AccessToken ;
6675
67- WriteVerbose ( "Retrieved Token: " + Token ) ;
76+ WriteVerbose ( "Retrieved Token: " + Token ) ;
77+ }
6878 }
79+ else if ( ClaimsDump . Contains ( "Token copied" ) )
80+ {
81+ Token = Clipboard . GetText ( ) . Replace ( "Bearer " , "" ) ;
82+ WriteVerbose ( "Got token from armclient: " + Token ) ;
83+ }
84+ else
85+ {
86+ return ;
87+ }
88+
89+
6990 var result = ConvertWithToken ( SubscriptionId , ResourceGroup , LogicApp , Token ) . Result ;
7091 WriteObject ( result . ToString ( ) ) ;
7192 }
0 commit comments