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

Use-PodeWebTemplates and authenticating with AAD #649

Open
slick789 opened this issue Jan 17, 2025 · 0 comments
Open

Use-PodeWebTemplates and authenticating with AAD #649

slick789 opened this issue Jan 17, 2025 · 0 comments
Labels
question ❔ Further information is requested

Comments

@slick789
Copy link

I am new to Pode development and am finding the framework really useful, however I have an issue around root I don't seem to be able to over come when using 'Use-PodeWebTemplates' and authenticating against Azure AD. When I run the PowerShell I get the following error:-
Exception: C:\Users\803100105\OneDrive - BT Plc\Documents\PowerShell\Modules\Pode\2.11.1\Private\Routes.ps1:521:9
Line |
521 | throw ($PodeLocale.methodPathAlreadyDefinedExceptionMessage - …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| [Get] /: Already defined.

I assume that root is already being referenced by "Use-PodeWebTemplates" and '/' as commenting out the template command works fine when authenticating against AAD, display "Authenticated". Has anybody got a solution as I want to re-use the default template with the sidebar and use 'Add-PodeWebPage' and 'New-PodeWebForm' commands instead of html pages as most of what I want to display from the template are forms? My code is below:-

`# Import Pode and Pode.Web modules
Import-Module Pode
Import-Module Pode.Web

Define the Azure AD Authentication settings

$ClientId = 'xxxxxxxxxxxxxxxxxxxxxx'
$TenantId = 'xxxxxxxxxxxxxxxxxxxxxx'
$ClientSecret = 'xxxxxxxxxxxxxxxxxxxxxxxx'

Start the Pode server

Start-PodeServer {
Add-PodeEndpoint -Address localhost -Port 8080 -Protocol Http

Use-PodeWebTemplates -Title "Utilities" -Theme Auto
    
# Setup session details
Enable-PodeSessionMiddleware -Duration 120 -Extend
    
# Setup authentication to validate a user
$scheme = New-PodeAuthAzureADScheme -ClientID $ClientId -ClientSecret $ClientSecret -Tenant $TenantId
    
$scheme | Add-PodeAuth -Name 'Login' -FailureUrl '/login' -SuccessUrl '/' -ScriptBlock {
    param($user, $accessToken, $refreshToken, $response)
    
    # Check if the user is valid
    return @{ User = $user }
}

# Home page: redirects to login page if not authenticated
Add-PodeRoute -Method Get -Path '/' -Authentication Login -ScriptBlock {
    Write-PodeTextResponse -Value "Authenticated!"
    # I want to be able to use:- 
    #Add-PodeWebPage -Name "Vend" -DisplayName "Vend Sub" -icon mdi-note-outline -ScriptBlock {
    #    New-PodeWebForm -Name "Sub" -SubmitText "Vend" -ShowReset -ResetText "Clear Form" -Content @(
    #        New-PodeWebTextbox -Name "OWNEREMAIL" -DisplayName "Owner Email" -Required -MaxLength 20 -Width 21 -Type "Email"
    #    ) -ScriptBlock {
    #        Show-PodeWebToast -Message "It works!" -Duration 6000 -Title "Success" -icon mdi-checkbox-marked-circle
    #    }
    #}
}

# Login - this will just redirect to Azure AD
Add-PodeRoute -Method Get -Path '/login' -Authentication Login
    
# Logout
Add-PodeRoute -Method Post -Path '/logout' -Authentication Login -Logout

}`

Any help would be very much appreciated!

@slick789 slick789 added the question ❔ Further information is requested label Jan 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question ❔ Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant