Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple Login Page Demo Using PSHTML and Polaris (PowerShell Modules)
Import-Module Polaris -Verbose
Import-Module PSHTML -Verbose
Add-Type -AssemblyName System.Web
New-PolarisGetRoute -Path "/Login" -Scriptblock {
$HTML = html {
head {
Title "Login Page"
}
body {
h1 -Content "Connect to Office365 Securely..."
Form -action "/authenticate" -method 'post' -target '_blank' -Content {
input -type text -name 'uSite'
input -type text -name 'uName'
input -type password -name 'uPassword'
button -Content "Click"
}
}
}
$Response.SetContentType('text/html')
$Response.Send($HTML)
}
New-PolarisPostRoute -Path "/authenticate" -Scriptblock {
$Response.SetContentType('application/json')
$Body = [System.Web.HttpUtility]::UrlDecode($Request.BodyString)
$Data = @{}
$Body.split('&') | ForEach-Object {
$part = $_.split('=')
$Data.add($part[0] , $part[1])
}
Import-Module C:\projects\iPolaris\assemblies\Microsoft.SharePoint.Client.dll
$UserName = $Data.uName
$Pasword = $Data.uPassword | ConvertTo-SecureString -AsPlainText -Force
$ClientContext = [Microsoft.SharePoint.Client.ClientContext]::new($Data.uSite)
$ClientContext.Credentials = [Microsoft.SharePoint.Client.SharePointOnlineCredentials]::new($UserName, $Pasword)
$ListCollection = $ClientContext.Web.Lists
$ClientContext.Load($ListCollection)
$ClientContext.ExecuteQuery()
$ClientContext.Dispose()
$Collection = @()
foreach ($List in $ListCollection | Select-Object -First 10) {
$Result = [pscustomobject]@{
Title = $List.Title
ItemCount = $List.ItemCount
}
$Collection += $Result
}
$Response.Send(($Collection | ConvertTo-Json))
}
Start-Polaris -Port 8080
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment