Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support usage without Azure AD app registration #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Get-MicrosoftTeamsChat.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
[cmdletbinding()]
Param(
[Parameter(Mandatory = $true, HelpMessage = "Export location of where the HTML files will be saved.")] [string] $ExportFolder,
[Parameter(Mandatory = $true, HelpMessage = "The client id of the Azure AD App Registration")] [string] $clientId,
[Parameter(Mandatory = $true, HelpMessage = "The tenant id of the Azure AD environment the user logs into")] [string] $tenantId,
[Parameter(Mandatory = $false, HelpMessage = "The client id of the Azure AD App Registration")] [string] $clientId = "31359c7f-bd7e-475c-86db-fdb8c937548e",
[Parameter(Mandatory = $false, HelpMessage = "The tenant id of the Azure AD environment the user logs into")] [string] $tenantId = "common",
[Parameter(Mandatory = $true, HelpMessage = "The domain name of the UPNs for users in your tenant. E.g. contoso.com")] [string] $domain
)

Expand Down
21 changes: 12 additions & 9 deletions functions/TelstraPurpleFunctions/TelstraPurpleFunctions.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,35 @@ function Get-TPASCII() {
}

function Connect-DeviceCodeAPI ($clientId, $tenantId, $refresh) {

$scope = "Chat.Read, User.Read, User.ReadBasic.All, offline_access"
if ([string]::IsNullOrEmpty($refresh)) {
$contentType = $null
$codeBody = @{

resource = "https://graph.microsoft.com/"
client_id = $clientId
scope = "Chat.Read, User.Read, User.ReadBasic.All, offline_access"

scope = $scope
}
if ($clientId -eq "31359c7f-bd7e-475c-86db-fdb8c937548e") {
$contentType = "application/x-www-form-urlencoded"
$codeBody = "client_id=$clientID&scope=https%3A%2F%2Fgraph.microsoft.com%2F%2F.default+offline_access+openid+profile"
}

$codeRequest = Invoke-RestMethod -Method POST -Uri "https://login.microsoftonline.com/$tenantId/oauth2/devicecode" -Body $codeBody

$codeRequest = Invoke-RestMethod -Method POST -Uri "https://login.microsoftonline.com/$tenantId/oauth2/v2.0/devicecode" -ContentType $contentType -Body $codeBody
# Print Code to console
Write-Host "`n$($codeRequest.message)"

$tokenBody = @{
grant_type = "urn:ietf:params:oauth:grant-type:device_code"
code = $codeRequest.device_code
device_code = $codeRequest.device_code
client_info = 1
client_id = $clientId

}
}
else {
$tokenBody = @{
grant_type = "refresh_token"
scope = "Chat.Read, User.Read, User.ReadBasic.All, offline_access"
scope = $scope
refresh_token = $refresh
client_id = $clientId
}
Expand All @@ -45,7 +48,7 @@ function Connect-DeviceCodeAPI ($clientId, $tenantId, $refresh) {
# Get OAuth Token
while ([string]::IsNullOrEmpty($tokenRequest.access_token)) {
$tokenRequest = try {
Invoke-RestMethod -Method POST -Uri "https://login.microsoftonline.com/$tenantId/oauth2/token" -Body $tokenBody
Invoke-RestMethod -Method POST -Uri "https://login.microsoftonline.com/$tenantId/oauth2/v2.0/token" -Body $tokenBody
}
catch {

Expand Down