Esempio n. 1
0
        internal static PnPConnection InstantiateManagedIdentityConnection(Cmdlet cmdlet, string tenantAdminUrl)
        {
            var httpClient  = PnP.Framework.Http.PnPHttpClient.Instance.GetHttpClient();
            var accesstoken = TokenHandler.GetManagedIdentityTokenAsync(cmdlet, httpClient, "https://graph.microsoft.com/").GetAwaiter().GetResult();
            var connection  = new PnPConnection(PnPPSVersionTag, InitializationType.Graph, tenantAdminUrl);

            return(connection);
        }
Esempio n. 2
0
 protected override void ProcessRecord()
 {
     try
     {
         ExecuteCmdlet();
     }
     catch (PnP.PowerShell.Commands.Model.Graph.GraphException gex)
     {
         if (gex.Error.Code == "Authorization_RequestDenied")
         {
             if (!string.IsNullOrEmpty(gex.AccessToken))
             {
                 TokenHandler.ValidateTokenForPermissions(GetType(), gex.AccessToken);
             }
         }
         throw new PSInvalidOperationException(gex.Error.Message);
     }
 }
Esempio n. 3
0
        protected override void ExecuteCmdlet()
        {
            var accessTokenValue = AccessToken;

            if (ParameterSetName == ResourceTypeParam)
            {
                accessTokenValue = null;

                switch (ResourceTypeName)
                {
                case ResourceTypeName.Graph:
                    accessTokenValue = AccessToken;
                    break;

                case ResourceTypeName.SharePoint:
                    accessTokenValue = TokenHandler.GetAccessToken(null, PnPConnection.Current?.Context?.Url?.TrimEnd('/') + "/.default");
                    break;

                case ResourceTypeName.ARM:
                    accessTokenValue = TokenHandler.GetAccessToken(null, "https://management.azure.com/.default");
                    break;
                }
            }
            else if (ParameterSetName == ResourceUrlParam)
            {
                accessTokenValue = TokenHandler.GetAccessToken(null, ResourceUrl);
            }

            if (Decoded.IsPresent)
            {
                WriteObject(new System.IdentityModel.Tokens.Jwt.JwtSecurityToken(accessTokenValue));
            }
            else
            {
                WriteObject(accessTokenValue);
            }
        }