Skip to content

Instantly share code, notes, and snippets.

View darrenjrobinson's full-sized avatar

Darren Robinson darrenjrobinson

View GitHub Profile
@darrenjrobinson
darrenjrobinson / AADAuth_MSAL_Python.py
Last active July 7, 2024 18:10
Microsoft Graph using MSAL with Python and Certificate Authentication. Associated blogpost https://blog.darrenjrobinson.com/microsoft-graph-using-msal-with-python-and-certificate-authentication/
import msal
import jwt
import json
import sys
import requests
from datetime import datetime
global accessToken
global requestHeaders
global tokenExpiry
{
"attributes": {
"authType": "Basic",
"username": "IdentityNowServiceAccount_in_ServiceNow",
"password": "IdentityNowServiceAccount_Password",
"url": "https://yourServiceNowTenant.service-now.com",
"serviceNowAppName" : "ServiceNow [source-42423]",
"catalogItem": {
"2c9180856a93cecd016a9ed337615c35": "a632c040db25f30033501c0e049619af"
}
@darrenjrobinson
darrenjrobinson / Interactive MSAL AAD Delegated AuthN.py
Last active May 31, 2024 15:44
Interactive Authentication to Microsoft Graph using MSAL with Python and Delegated Permissions. See associated blogpost https://blog.darrenjrobinson.com/interactive-authentication-to-microsoft-graph-using-msal-with-python-and-delegated-permissions/
import msal
import jwt
import json
import sys
import requests
from datetime import datetime
from msal_extensions import *
# Microsoft Azure PowerShell Client ID
clientID = '1950a258-227b-4e31-a9cf-717495945fc2'
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
param (
$Username,
$Password,
$OperationType,
[bool] $usepagedimport,
$pagesize
)
#Needs reference to .NET assembly used in the script.
Function DelegatedAuthN {
<#
.SYNOPSIS
Authenticate to Azure AD (using Delegated Auth) and receieve Access and Refresh Tokens.
.DESCRIPTION
Authenticate to Azure AD (using Delegated Auth) and receieve Access and Refresh Tokens.
.PARAMETER tenantID
@darrenjrobinson
darrenjrobinson / Get-Unifi-Details.ps1
Last active June 30, 2023 08:28
PowerShell Script to get Ubiquiti Unifi Sites, Devices and Active Clients. Associated blogpost https://blog.darrenjrobinson.com/accessing-your-ubiquiti-unifi-network-configuration-with-powershell/
# Unifi Controller Login Base URI
$uController = 'yourControllerIP' # e.g 'https://192.168.1.2:8443'
# Identifier of the site in UniFi. Set to default for the default site
$uSiteID = "default"
$uUsername = 'adminuser' # yourAdmin UserID
$uPassword = 'yourPassword' # yourAdmin User Password
$uAuthBody = @{"username" = $uUsername; "password" = $uPassword }
$uHeaders = @{"Content-Type" = "application/json" }
@darrenjrobinson
darrenjrobinson / Microsoft Graph using MSAL with Python and Delegated Permissions.py
Last active May 1, 2023 13:59
Microsoft Graph using MSAL with Python and Delegated Permissions using a persistent local MSAL Cache. Associated Blogpost https://blog.darrenjrobinson.com/microsoft-graph-using-msal-with-python-and-delegated-permissions/
import msal
import jwt
import json
import sys
import requests
from datetime import datetime
from msal_extensions import *
graphURI = 'https://graph.microsoft.com'
tenantID = 'yourTenantID'
@darrenjrobinson
darrenjrobinson / Set PowerShellAI OpenAI API Credential.ps1
Last active April 26, 2023 00:21
Set PowerShellAI OpenAI API Credentials Securely on Windows. Associated blogpost https://blog.darrenjrobinson.com/generative-ai-chatgpt-with-powershell/
# 1. Get API Credential via prompt.
# Only need the password which is your API Key
$gptAPI = Get-Credential
# 2. Export to a file in the local directory
$gptAPI | Export-Clixml ./chatGPTAPIKey.xml
# 3. Ongoing you only need to put the following two lines at the top of your scripts
# Make sure you copy your chatGPTAPIKey.xml file to other directories for scripts for OpenAI.
$chatGPTCred = Import-Clixml .\chatGPTAPIKey.xml
@darrenjrobinson
darrenjrobinson / Simplified Set PowerShellAI OpenAI API Credential.ps1
Last active April 26, 2023 00:20
Simplified Set PowerShellAI OpenAI API Credentials Securely on Windows. Associated blogpost https://blog.darrenjrobinson.com/generative-ai-chatgpt-with-powershell/
# 1. Import the OpenAI API Key from the local securely exported credential
$chatGPTCred = Import-Clixml .\chatGPTAPIKey.xml
# 2. Use the Set-OpenAIKey cmdlet to take the secure credential and set the OpenAIKey environment variable
Set-OpenAIKey -Key $chatGPTCred.Password
# 3. Import the PowerShellAI Module
Import-Module PowerShellAI