My ultimate goal is getting MS Graph working with LWP and Perl. For better understanding I start out by sandboxing it on the command line with curl. This from a firm believe that if I can get it going on the command line I can get it working anywhere.

So why curl? Well:

  • it’s documented rather good.
  • It has been around like forever
  • and is the absolute no-brainer on doing HTTP (among many other) requests from the command line. There are even libraries to use curl from within a Perl script.

I came up with the following bash script it do just that:

#! /usr/bin/bash

 token=`curl \
    -d grant_type=client_credentials \
    -d client_id=[client_id] \
    -d client_secret=[client_secret] \
    -d scope= \
    -d resource= \[tenant_id]/oauth2/token \
    | jq -j .access_token`

curl -X GET \
    -H "Authorization: Bearer $token" \
    -H "Content-Type: application/json" \ \
    | jq .

I’ve put two curl commands in a bash script:

  • The first is a request for a token which is stored in a variable
  • By using this token I make a second request to get a list of groups from the tenant.

You will have to fill in the blanks yourself of course, the things like [client_secret]. The curl output is piped through jq to parse the (JSON) output. Getting a listing of groups is just an example.

laat een reactie achter

Deze site gebruikt Akismet om spam te verminderen. Bekijk hoe je reactie-gegevens worden verwerkt.