Microsoft Teams 集成到 Moodle LMS 中

Microsoft Teams integration into Moodle LMS

大家好!我在将 Microsoft Teams 集成到 Moodle 中时遇到错误。因此,集成步骤之一是 运行 Moodle-AzureAD-Script.ps1 本地计算机上的脚本。当我尝试 运行 脚本时出现错误:“./Moodle-AzureAD-Script.ps1: 第 1 行:意外标记附近的语法错误 newline' '/Moodle-AzureAD-Script.ps1: line 1: <# "; 它不依赖于 OS,所以有人可以告诉我,我该怎么办?谢谢!

Moodle-AzureAD-Script。ps1 脚本可从 https://moodle.org/plugins/pluginversions.php?plugin=local_o365

下载
<#
    File Name :  Moodle-AzureAD-Script.ps1
    
    Copyright (c) Microsoft Corporation. All rights reserved.
    Licensed under the MIT License.
#>


# Allow for the script to be run
Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope CurrentUser

# Install necessary modules
Install-Module AzureAD -AllowClobber -Scope CurrentUser
Install-Module AzureRM -AllowClobber -Scope CurrentUser

#Overarching requirement - log into Azure first!
Connect-AzureAD

<#
.DESCRIPTION 

This function will be able to create an array of type RequiredResourceAccess which will be then passed to the New-AzureADApplication cmdlet
#>
function Get-Resources
{
    [Microsoft.Open.AzureAD.Model.RequiredResourceAccess[]] $outputArray = @();
    
    $localPath = Get-Location
    $jsonPath = -Join($localPath,'\Json\permissions.json');
    $jsonObj = (New-Object System.Net.WebClient).DownloadString($jsonPath) | ConvertFrom-Json;

    # Output the number of objects to push into the array outputArray
    Write-Host 'From the json path:'$jsonPath', we can find' $jsonObj.requiredResourceAccess.length'attributes to populate';

    for ($i = 0; $i -lt $jsonObj.requiredResourceAccess.length; $i++) {
        
        # Step A - Create a new object fo the type RequiredResourceAccess
        $reqResourceAccess = New-Object -TypeName Microsoft.Open.AzureAD.Model.RequiredResourceAccess; 

        # Step B - Straightforward setting the ResourceAppId accordingly
        $reqResourceAccess.ResourceAppId = $jsonObj.requiredResourceAccess[$i].resourceAppId;

        # Step C - Having to set the ResourceAccess carefully
        if ($jsonObj.requiredResourceAccess[$i].resourceAccess.length -gt 1)
        {
            $reqResourceAccess.ResourceAccess = $jsonObj.requiredResourceAccess[$i].resourceAccess;
        }
        else
        {
            $reqResourceAccess.ResourceAccess = $jsonObj.requiredResourceAccess[$i].resourceAccess[0];
        }

        # Step D - Add the element to the array
        $outputArray += $reqResourceAccess;
    }

    $outputArray;
}

# Step 1 - Getting the necessary information
$displayName = Read-Host -Prompt "Enter the AAD app name (ex: Moodle plugin)"
$moodleDomain = Read-Host -Prompt "Enter the URL of your Moodle server (ex: https://www.moodleserver.com)"

if ($moodleDomain -notmatch '.+?\/$')
{
    $moodleDomain += '/'
}

# Step 2 - Construct the reply URLs
$ssoEndUrl = $moodleDomain + 'local/o365/sso_end.php'
$ssoUrl = $moodleDomain + 'local/o365/sso.php'
$ssoLogoutUrl = $moodleDomain + 'local/o365/sso_logout.php'
$botFrameworkUrl = 'https://token.botframework.com/.auth/web/redirect'
$authUrl = $moodleDomain + 'auth/oidc/'

$replyUrls = ($ssoEndUrl, $ssoUrl, $botFrameworkUrl, $authUrl)

# Step 3 - Compile the Required Resource Access object
[Microsoft.Open.AzureAD.Model.RequiredResourceAccess[]] $requiredResourceAccess = Get-Resources

# Step 4 - Making sure to officially register the application
$appVars = New-AzureADApplication -DisplayName $displayName -ReplyUrls $replyUrls -RequiredResourceAccess $requiredResourceAccess -LogoutUrl $ssoLogoutUrl

# Step 5 - Taking the object id generated in Step 2, create a new Password
$pwdVars = New-AzureADApplicationPasswordCredential -ObjectId $appVars.ObjectId

# Step 5a - Updating the logo for the Azure AD app
$location = Get-Location
$imgLocation = -Join($location, '\Assets\moodle-logo.jpg')

Set-AzureADApplicationLogo -ObjectId $appVars.ObjectId -FilePath $imgLocation

# Step 6 - Write out the newly generated app Id and azure app password
Write-Host 'Your AD Application ID: '$appVars.AppId
Write-Host 'Your AD Application Secret: '$pwdVars.Value

事实上,脚本完全取决于OS。

请注意\o365\scripts路径下的README.md文件

它指出:

Requirements

  • This script requires a Windows 7+ device. MacOS/Linux devices are NOT supported.
  • This script is only compatible with Windows Powershell 5, which is pre-installed on each Windows 7+ device. Powershell 6+ is NOT supported.

确保 OS 和 Powershell 版本正常,然后您就可以按照此 README.md 文件中的指南完成集成。