Skip to content

Commit b6d0cc6

Browse files
authored
Merge pull request #1176 from Badgerati/develop
v2.9.0
2 parents b6a97d2 + 7459f73 commit b6d0cc6

File tree

137 files changed

+7625
-4669
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

137 files changed

+7625
-4669
lines changed

.github/CONTRIBUTING.md

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,34 @@ The following is a set of guidelines for contributing to Pode on GitHub. These a
66

77
## Table of Contents
88

9-
* [Code of Conduct](#code-of-conduct)
10-
* [I just have a Question](#i-just-have-a-question)
11-
* [About Pode](#about-pode)
12-
* [How to Contribute](#how-to-contribute)
13-
* [Issues](#issues)
14-
* [Branch Names](#branch-names)
15-
* [Pull Requests](#pull-requests)
16-
* [Building](#building)
17-
* [Testing](#testing)
18-
* [Documentation](#documentation)
19-
* [Styleguide](#styleguide)
20-
* [Code](#code)
21-
* [Comments](#comments)
22-
* [General](#general)
23-
* [Help](#help)
24-
* [PowerShell Commandlets](#powershell-commandlets)
25-
* [Foreach-Object](#foreach-object)
26-
* [Where-Object](#where-object)
27-
* [Select-Object](#select-object)
28-
* [Measure-Object](#measure-object)
9+
- [Contributing to Pode](#contributing-to-pode)
10+
- [Table of Contents](#table-of-contents)
11+
- [Code of Conduct](#code-of-conduct)
12+
- [I just have a Question](#i-just-have-a-question)
13+
- [About Pode](#about-pode)
14+
- [How to Contribute](#how-to-contribute)
15+
- [Issues](#issues)
16+
- [Branch Names](#branch-names)
17+
- [Pull Requests](#pull-requests)
18+
- [Building](#building)
19+
- [Testing](#testing)
20+
- [Documentation](#documentation)
21+
- [Importing](#importing)
22+
- [Styleguide](#styleguide)
23+
- [Editor](#editor)
24+
- [Code](#code)
25+
- [Comments](#comments)
26+
- [General](#general)
27+
- [Help](#help)
28+
- [PowerShell Commandlets](#powershell-commandlets)
29+
- [Foreach-Object](#foreach-object)
30+
- [Where-Object](#where-object)
31+
- [Select-Object](#select-object)
32+
- [Measure-Object](#measure-object)
2933

3034
## Code of Conduct
3135

32-
This project and everyone participating in it is governed by the Pode's [Code of Conduct](../.github/CODE_OF_CONDUCT.md). By participating, you are expected to uphold this code.
36+
This project, and everyone participating in it, is governed by the Pode's [Code of Conduct](../.github/CODE_OF_CONDUCT.md). By participating, you are expected to uphold this code.
3337

3438
## I just have a Question
3539

@@ -111,22 +115,20 @@ When editing Pode and you need to import the local dev module for testing, you w
111115

112116
## Styleguide
113117

118+
### Editor
119+
120+
You can use whatever editor you like, but it's recommended to use Visual Studio Code. To help with this style guide, specifically for PowerShell, Pode has code formatting workspace setting which will automatically format the files on save.
121+
114122
### Code
115123

116124
In general, observe the coding style used within the file/project and mimic that as best as you can. Some standards that are typical are:
117125

118-
* Bracers (`{}`) on the function header should be on a new line, such as:
126+
* Bracers (`{}`) should be on the same line of the statement they following, such as `function`, `foreach`, `if`, etc.
119127
```powershell
120-
function Add-Something
121-
{
122-
# logic
123-
}
124-
```
125-
126-
* Bracers (`{}`) should be on the same line of other calls, such as `foreach`, `if`, etc.
127-
```powershell
128-
foreach ($item in $items) {
129-
# logic
128+
function Add-Something {
129+
foreach ($item in $items) {
130+
# logic
131+
}
130132
}
131133
```
132134

@@ -135,8 +137,7 @@ foreach ($item in $items) {
135137
* Ensure public functions always declare `[CmdletBinding()]` attribute.
136138
* Ensure parameter names, types, and attributes are declared on new lines - not all on one line.
137139
```powershell
138-
function Add-Something
139-
{
140+
function Add-Something {
140141
[CmdletBinding()]
141142
param(
142143
[Parameter()]

.vscode/settings.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"editor.formatOnSave": true,
3+
"editor.formatOnType": false,
4+
"editor.minimap.enabled": false,
5+
"powershell.codeFormatting.addWhitespaceAroundPipe": true,
6+
"powershell.codeFormatting.alignPropertyValuePairs": true,
7+
"powershell.codeFormatting.autoCorrectAliases": true,
8+
"powershell.codeFormatting.avoidSemicolonsAsLineTerminators": true,
9+
"powershell.codeFormatting.ignoreOneLineBlock": true,
10+
"powershell.codeFormatting.pipelineIndentationStyle": "IncreaseIndentationForFirstPipeline",
11+
"powershell.codeFormatting.trimWhitespaceAroundPipe": true,
12+
"powershell.codeFormatting.useConstantStrings": true,
13+
"powershell.codeFormatting.whitespaceBeforeOpenBrace": true,
14+
"powershell.codeFormatting.whitespaceAroundOperator": true,
15+
"powershell.codeFormatting.whitespaceAfterSeparator": true,
16+
"powershell.codeFormatting.useCorrectCasing": false,
17+
"powershell.codeFormatting.openBraceOnSameLine": true,
18+
"powershell.codeFormatting.newLineAfterOpenBrace": true,
19+
"powershell.codeFormatting.newLineAfterCloseBrace": true,
20+
"powershell.codeFormatting.whitespaceBeforeOpenParen": true,
21+
"powershell.codeFormatting.whitespaceBetweenParameters": false,
22+
"powershell.codeFormatting.whitespaceInsideBrace": true,
23+
"files.trimTrailingWhitespace": true
24+
}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ Then navigate to `http://127.0.0.1:8000` in your browser.
6767
* Basic rate limiting for IP addresses and subnets
6868
* Middleware and Sessions on web servers, with Flash message and CSRF support
6969
* Authentication on requests, such as Basic, Windows and Azure AD
70+
* Authorisation support on requests, using Roles, Groups, Scopes, etc.
7071
* Support for dynamically building Routes from Functions and Modules
7172
* Generate/bind self-signed certificates
7273
* Secret management support to load secrets from vaults

alpine.dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM mcr.microsoft.com/powershell:7.3-alpine-3.15
1+
FROM mcr.microsoft.com/powershell:7.3-alpine-3.17
22
LABEL maintainer="Matthew Kelly (Badgerati)"
33
RUN mkdir -p /usr/local/share/powershell/Modules/Pode
44
COPY ./pkg/ /usr/local/share/powershell/Modules/Pode

arm32.dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM mcr.microsoft.com/powershell:preview-7.3-arm32v7-ubuntu-18.04
1+
FROM mcr.microsoft.com/powershell:7.3-ubuntu-22.04-arm32
22
LABEL maintainer="Matthew Kelly (Badgerati)"
33
RUN mkdir -p /usr/local/share/powershell/Modules/Pode
44
COPY ./pkg/ /usr/local/share/powershell/Modules/Pode

docs/Getting-Started/Migrating/0X-to-1X.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ There is a new [`New-PodeMiddleware`](../../../Functions/Middleware/New-PodeMidd
186186

187187
([Tutorial](../../../Tutorials/Middleware/Types/Sessions))
188188

189-
The `session` function has now been replaced by the new [`Enable-PodeSessionMiddleware`](../../../Functions/Middleware/Enable-PodeSessionMiddleware) function. With the new function, not only will it automatically enabled session middleware for you, but the old `-Options` hashtable has now been converted into proper function parameters.
189+
The `session` function has now been replaced by the new [`Enable-PodeSessionMiddleware`](../../../Functions/Sessions/Enable-PodeSessionMiddleware) function. With the new function, not only will it automatically enabled session middleware for you, but the old `-Options` hashtable has now been converted into proper function parameters.
190190

191191
### CSRF
192192

docs/Hosting/IIS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ This allows you to write a Pode server that works locally, but will also automat
129129
!!! note
130130
This does mean that Pode will force all endpoints to `127.0.0.1:PORT`. So if you had two different IPs before, they'll be merged into one. Something to be aware of if you assign routes to specific endpoints, as under IIS this won't work.
131131

132+
### Maximum Worker Processes
133+
134+
Unless you're using an external data store for sessions, ensure the Maximum Worker Processes is 1. Each worker process will spawn a new instance of your Pode server, and if using Pode's inbuilt session storage you'll face authenticated/session timeout issues when one instance doesn't contain the right session.
135+
132136
### Advanced/Domain/Kerberos
133137

134138
The above IIS site setup works, but only for simple sites. If you require the use of the Active Directory module, or your site to be running as a different user then follow the steps below.

docs/Tutorials/Authentication/Inbuilt/AzureAD.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ To setup and start using Azure AD authentication in Pode you use `New-PodeAuthAz
4141

4242
```powershell
4343
Start-PodeServer {
44+
Enable-PodeSessionMiddleware -Duration 120 -Extend
45+
4446
$scheme = New-PodeAuthAzureADScheme -ClientID '<clientId>' -ClientSecret '<clientSecret>' -Tenant '<tenant>'
4547
4648
$scheme | Add-PodeAuth -Name 'Login' -FailureUrl '/login' -SuccessUrl '/' -ScriptBlock {
@@ -63,6 +65,8 @@ To setup Azure AD authentcation, but using your own Form login, then you can use
6365

6466
```powershell
6567
Start-PodeServer {
68+
Enable-PodeSessionMiddleware -Duration 120 -Extend
69+
6670
$form = New-PodeAuthScheme -Form
6771
6872
$scheme = New-PodeAuthAzureADScheme -ClientID '<clientId>' -ClientSecret '<clientSecret>' -Tenant '<tenant>' -InnerScheme $form
@@ -97,7 +101,7 @@ The Pode side needs to be configured to allow basic authentication as well. This
97101
$form = New-PodeAuthScheme -Form
98102
$schemeForm = New-PodeAuthAzureADScheme -ClientID '<clientId>' -ClientSecret '<clientSecret>' -Tenant '<tenant>' -InnerScheme $form
99103
100-
$basic = New-PodeAuthSceme -Basic
104+
$basic = New-PodeAuthScheme -Basic
101105
$schemeBasic = New-PodeAuthAzureADScheme -ClientID '<clientId>' -ClientSecret '<clientSecret>' -Tenant '<tenant>' -InnerScheme $basic
102106
103107
$authLogin = {
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Sessions
2+
3+
Pode has support for Sessions when using Authentication, by default if you call a Route with authentication and you already have a session on the request then you're "authenticated". If there's no session, then the authentication logic is invoked, and if the details are invalid you're redirected to a login screen.
4+
5+
If you have a need to use multiple authentication methods for login, and the user can chose the one they want, then on Routes there's no simple way of say which authentication is required. However, under the hood they all create a session object which can be used as a "shared" authentication method.
6+
7+
This sessions authenticator can be used to pass authentication if a valid session in on the request, or to automatically redirect to a login page if there is no valid session. Useful for if you're using multiple authentication methods the user can choose from.
8+
9+
## Usage
10+
11+
To add sessions authentication you can use [`Add-PodeAuthSession`](../../../../Functions/Authentication/Add-PodeAuthSession). The following example will validate a user's credentials on login using Form authentication, but the home page uses session authentication to just verify there's a valid session:
12+
13+
```powershell
14+
Start-PodeServer {
15+
# endpoint and view engine
16+
Add-PodeEndpoint -Address * -Port 8085 -Protocol Http
17+
Set-PodeViewEngine -Type Pode
18+
19+
# enable sessions
20+
Enable-PodeSessionMiddleware -Duration 120 -Extend
21+
22+
# setup form auth for login
23+
New-PodeAuthScheme -Form | Add-PodeAuth -Name 'FormAuth' -FailureUrl '/login' -SuccessUrl '/' -ScriptBlock {
24+
param($username, $password)
25+
26+
# here you'd check a real user storage, this is just for example
27+
if ($username -eq 'morty' -and $password -eq 'pickle') {
28+
return @{ User = @{ Name = 'Morty' } }
29+
}
30+
31+
return @{ Message = 'Invalid details supplied' }
32+
}
33+
34+
# setup session auth for routes and logout
35+
Add-PodeAuthSession -Name 'SessionAuth' -FailureUrl '/login'
36+
37+
# home page: use session auth, and redirect to login if no valid session
38+
Add-PodeRoute -Method Get -Path '/' -Authentication SessionAuth -ScriptBlock {
39+
Write-PodeViewResponse -Path 'auth-home'
40+
}
41+
42+
# login page: use form auth here to actually verify the user's credentials
43+
Add-PodeRoute -Method Get -Path '/login' -Authentication FormAuth -Login -ScriptBlock {
44+
Write-PodeViewResponse -Path 'auth-login' -FlashMessages
45+
}
46+
47+
# login check: again, use form auth
48+
Add-PodeRoute -Method Post -Path '/login' -Authentication FormAuth -Login
49+
50+
# logout - use session auth here to purge the session
51+
Add-PodeRoute -Method Post -Path '/logout' -Authentication SessionAuth -Logout
52+
}
53+
```
54+
55+
### User Object
56+
57+
If a valid session is found on the request, then the user object set at `$WebEvent.Auth.User` will take the form of which ever authentication method using for login.
58+
59+
The user object will simply be loaded from the session.

docs/Tutorials/Authentication/Inbuilt/UserFile.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ Start-PodeServer {
6262
Regardless of whether the password is a standard SHA256 hash or HMAC hash, the hashed output should be a base64 string. The following functions will return the hashed value in the expected format:
6363

6464
**SHA256 HASH**:
65+
6566
```powershell
6667
function ConvertTo-SHA256([string]$String)
6768
{
@@ -73,6 +74,7 @@ function ConvertTo-SHA256([string]$String)
7374
```
7475

7576
**HMAC HASH:**
77+
7678
```powershell
7779
function ConvertTo-HMACSHA256([string]$String, [string]$Secret) {
7880
$HMACSHA256 = New-Object System.Security.Cryptography.HMACSHA256

docs/Tutorials/Authentication/Inbuilt/WindowsAD.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,7 @@ New-PodeAuthScheme -Form | Add-PodeAuthWindowsAd -Name 'Login' -ScriptBlock {
149149
return @{ Message = 'Authorisation failed' }
150150
}
151151
```
152+
153+
## Protected Users
154+
155+
In Windows AD there is a "Protected Users" group that you can assign users into. If users in this group are trying to use your site, then they will fail authentication. Unfortunately, this is just a secure feature of Windows AD, and the only way around this is to take the affected users out of the Protected Users group.

docs/Tutorials/Authentication/Methods/Bearer.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ To start using Bearer authentication in Pode you can use `New-PodeAuthScheme -Be
1212

1313
```powershell
1414
Start-PodeServer {
15-
New-PodeAuthScheme -Bearer | Add-PodeAuth -Name 'Authenticate' -ScriptBlock {
15+
New-PodeAuthScheme -Bearer | Add-PodeAuth -Name 'Authenticate' -Sessionless -ScriptBlock {
1616
param($token)
1717
1818
# check if the token is valid, and get user

0 commit comments

Comments
 (0)