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

OAuth2 state returned is invalid (Authorisation Code) #1217

Open
atriumcarceri opened this issue Dec 27, 2023 · 0 comments
Open

OAuth2 state returned is invalid (Authorisation Code) #1217

atriumcarceri opened this issue Dec 27, 2023 · 0 comments

Comments

@atriumcarceri
Copy link

Hello there.
So after some years i made some service with oauth, but code that worked two years ago dont work now.
After success auth on keycloak page got first redirect to / with 401 '⚠️ unknown_error:', after refresh or go on any another existing route got 401 "⚠️ OAuth2 state returned is invalid" with perma redirect to url like this

/?state=34722157-444f-40eb-8324-2d2e382e598f&session_state=7411799c-e023-4c2e-b1b5-08a436f98575&code=6ea9098a-9132-4690-8fe0-b876673d2e31.7411799c-e023-4c2e-b1b5-08a436f98575.bfe1112f-e8c2-4a31-8855-87e1bf561291

Session appear in keycloak client session list and pode set cookie pode.sid

$scheme = New-PodeAuthScheme  -OAuth2 `
                    -ClientID 'client-id-3' `
                    -ClientSecret 'supersercretpassword' `
                    -TokenUrl 'https://kc.domain/auth/realms/internal/protocol/openid-connect/token' `
                    -AuthoriseUrl 'https://kc.domain/auth/realms/internal/protocol/openid-connect/auth' `
                    -UserUrl 'https://kc.domain/auth/realms/internal/protocol/openid-connect/userinfo' `
                    -RedirectUrl 'https://dev.internal.org/'
$scheme | Add-PodeAuth -Name 'id' -SuccessUrl '/' -ScriptBlock {
                param($user, $accessToken, $refreshToken, $response)
                return @{ 
                    Username = $user
                }
            }
Enable-PodeSessionMiddleware -Duration 600 -Extend
Add-PodeRoute -Method Get -Path '/' -Authentication id -ScriptBlock {
    Write-PodeJsonResponse -Value @{ 'value' = 'test' }
}
Add-PodeAuthMiddleware -Name 'GlobalAuthValidation' -Authentication id
Add-PodeRoute -Method Get -Path '/login' -Authentication 'id'
Add-PodeRoute -Method Post -Path '/logout' -Authentication 'id' -Logout

So error goes from this condition:
Private/Authentication.ps1
if ((Test-PodeSessionsInUse) -and ($WebEvent.Query['state'] -ne $WebEvent.Session.Data['__pode_oauth_state__'])) {

What am i doing wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant