Skip to content

Instantly share code, notes, and snippets.

@mjendza
Created December 8, 2023 09:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mjendza/102bf99a1721710faf9a7690b0cec8c2 to your computer and use it in GitHub Desktop.
Save mjendza/102bf99a1721710faf9a7690b0cec8c2 to your computer and use it in GitHub Desktop.
ClientCredential-1PasswordCLI-sample.ps1
#LINK 1Password secrets to the environment variables
$ENV:FL_SP_CLIENT_ID = "op://Factorlabs/Factorlabs Service Principal for 1password demo/username"
$ENV:FL_SP_CLIENT_SECRET = "op://Factorlabs/Factorlabs Service Principal for 1password demo/password"
$client_id = $env:FL_SP_CLIENT_ID
$client_secret = $env:FL_SP_CLIENT_SECRET
$tenant_id = "6790fadf-1111-4f73-8f65-844675b9a99a"
$resource = [uri]::EscapeDataString("https://graph.microsoft.com/.default")
$tokenUrl = "https://login.microsoftonline.com/$tenant_id/oauth2/token"
$Body = "grant_type=client_credentials&client_id=$client_id&client_secret=$client_secret&scope=$resource"
Write-Output $Body
$Headers = @{
'Content-Type' = 'application/x-www-form-urlencoded'
}
curl $tokenUrl -H $Headers -body $Body -Method 'POST'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment