-
-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#472: initial work for gets client certs and auth working
- Loading branch information
Showing
10 changed files
with
133 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
$path = Split-Path -Parent -Path (Split-Path -Parent -Path $MyInvocation.MyCommand.Path) | ||
Import-Module "$($path)/src/Pode.psm1" -Force -ErrorAction Stop | ||
|
||
# or just: | ||
# Import-Module Pode | ||
|
||
# create a server, flagged to generate a self-signed cert for dev/testing, but allow client certs for auth | ||
Start-PodeServer { | ||
|
||
# bind to ip/port and set as https with self-signed cert | ||
Add-PodeEndpoint -Address * -Port 8443 -Protocol Https -SelfSigned -AllowClientCertificate | ||
|
||
# set view engine for web pages | ||
Set-PodeViewEngine -Type Pode | ||
|
||
# setup client cert auth | ||
New-PodeAuthScheme -ClientCertificate | Add-PodeAuth -Name 'Validate' -Sessionless -ScriptBlock { | ||
param($cert, $errors) | ||
|
||
# validate the thumbprint - here you would check a real cert store, or database | ||
if ($cert.Thumbprint -ieq '2561B2BD3CF292FF55F72692FB252E6B3D9879C2') { | ||
return @{ | ||
User = @{ | ||
ID ='M0R7Y302' | ||
Name = 'Morty' | ||
Type = 'Human' | ||
} | ||
} | ||
} | ||
|
||
# an invalid cert | ||
return @{ Message = 'Invalid certificate supplied' } | ||
} | ||
|
||
# GET request for web page at "/" | ||
Add-PodeRoute -Method Get -Path '/' -Authentication 'Validate' -ScriptBlock { | ||
param($e) | ||
#$e.Request.ClientCertificate | out-default | ||
Write-PodeViewResponse -Path 'simple' -Data @{ 'numbers' = @(1, 2, 3); } | ||
} | ||
|
||
# GET request throws fake "500" server error status code | ||
Add-PodeRoute -Method Get -Path '/error' -Authentication 'Validate' -ScriptBlock { | ||
param($e) | ||
Set-PodeResponseStatus -Code 500 | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters