GithubHelp home page GithubHelp logo

minigraph's Introduction

MiniGraph

Introduction

The MiniGraph module is designed as a minimal overhead Microsoft Graph client implementation. It is intended for lean environments such as Azure Functions where a maximum performance in all aspects is required.

Installation

The module has been published to the PowerShell Gallery. To install it, run:

Install-Module MiniGraph

Use

Authenticate

First you need to authenticate. Three authentication workflows are provided:

  • Application: Certificate
  • Application: Secret
  • Delegate: Username & Password

For example, the connection with a certificate object could work like this:

$cert = Get-Item -Path 'Cert:\CurrentUser\My\082D5CB4BA31EED7E2E522B39992E34871C92BF5'
Connect-GraphCertificate -TenantID '0639f07d-76e1-49cb-82ac-abcdefabcdefa' -ClientID '0639f07d-76e1-49cb-82ac-1234567890123' -Certificate $cert

Execute

After connecting to graph, execute queries like this:

# Return all groups
Invoke-GraphRequest -Query groups

You can now basically follow the guidance in the graph api reference and take it from there.

Graph Beta Endpoint

If you need to work against the beta endpoint, switching to that for the current session can be done like this:

Set-GraphEndpoint -Type beta

Common Issues

Scopes

Make sure you verify the scopes (permissions) needed for a request. They must be assigned as Api Permission in the registered application in the Azure portal. Admin Consent must be given for Application permissions. For delegate permissions, either Admin Consent or User Consent must have been granted, as Connect-GraphCredential does not support any mechanisms to request Consent.

Must contain client_assertion or client_secret

This usually happens when trying to connect with credentials. The registered application must be configured for this authentication type in the authentication tab:

  • In Platform configurations, add a Web Platform with redirect URI "http://localhost"
  • In Advanced settings, enable "Allow public client flows"

minigraph's People

Contributors

friedrichweinmann avatar nyanhp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

minigraph's Issues

cmdlet naming collision

MicrosoftTeams-image

Name collision - does it make sense to rename the cmdlet to Invoke-MiniGraphRequest?

Cheers,
David

"error_description":"AADSTS50027: JWT token is invalid or malformed

Hi Fred,

I'm getting an issue with the v1.0.2 module:

You cannot call a method on a null-valued expression.
At C:\Program Files\WindowsPowerShell\Modules\minigraph\1.0.2\MiniGraph.psm1:129 char:4

  •         $outBytes = $Certificate.PrivateKey.SignData($inBytes, $A ...
    
  •         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (:) [], RuntimeException
    • FullyQualifiedErrorId : InvokeMethodOnNull

Exception calling "ToBase64String" with "1" argument(s): "Value cannot be null.
Parameter name: inArray"
At C:\Program Files\WindowsPowerShell\Modules\minigraph\1.0.2\MiniGraph.psm1:130 char:4

  •         [convert]::ToBase64String($outBytes)
    
  •         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    • FullyQualifiedErrorId : ArgumentNullException

Invoke-RestMethod : {"error":"invalid_request","error_description":"AADSTS50027: JWT token is invalid or malformed.\r\nTrace ID: d04f63eb-cdd1-4164-936e-675267d91700\r\nCorrelation ID: 6dc79eec-a7b1-4c26-99ed-cea9340accd3\r\nTimestamp:
2021-12-02 15:58:24Z","error_codes":[50027],"timestamp":"2021-12-02
15:58:24Z","trace_id":"d04f63eb-cdd1-4164-936e-675267d91700","correlation_id":"6dc79eec-a7b1-4c26-99ed-cea9340accd3","error_uri":"https://login.microsoftonline.com/error?code=50027"}
At C:\Program Files\WindowsPowerShell\Modules\minigraph\1.0.2\MiniGraph.psm1:203 char:25

  • ... pt:token = (Invoke-RestMethod -Uri $uri -Method Post -Body $body -Hea ...
  •             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
    • FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

Please can you take a look when you have a moment, thanks Greg.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.