Comments (4)
Unclear what's causing this.
The OAuth2Flow
flow works as follows:
- If no state is in session or no state parameter is passed, start authorization flow by:
a. creating 32 random bytes as state
b. storing them in the session
b. redirecting the user to the authorization page, appending the state - The authorization page now performs its duty and redirects back to us, passing back the state
- If the session state matches the state parameter, exchange the auth code for an access token by:
a. performing a post-back to the authorization page
b. storing the returned access token in the session
c. redirecting to ourselves, removing the URL parameters from step 2 - Read (and subsequently remove) the access token from the session, returning flow control
We can reach this "flow error" condition if step 2 fails to return the state we passed (very unlikely in this case, it would be a O365 SSO error), or if the session value gets exchanged with a different value while steps 2..4 haven't completed yet.
from web-auth.
...or if the session value gets exchanged with a different value while steps 2..4 haven't completed yet.
A new value is generated when a) no state is in session... (error message above rules this out)
or b) no state parameter is passed.
So basically if I do the following:
- Open the app URL, follow the redirect. This creates the session value and passes it to the SSO.
- In a new tab, open the app URL. This changes the session value.
- Go back to the first tab and continue authenticating there. The SSO passes back the value created during step 1
For this to work, the SSO may not immediately redirect back in step 1, that is, we need to log out.
from web-auth.
I haven't been able to reproduce the issue, but we should be able to fix this issue as follows:
diff --git a/src/main/php/web/auth/oauth/OAuth2Flow.class.php b/src/main/php/web/auth/oauth/OAuth2Flow.class.php
index 50d3f48..544dbd9 100755
--- a/src/main/php/web/auth/oauth/OAuth2Flow.class.php
+++ b/src/main/php/web/auth/oauth/OAuth2Flow.class.php
@@ -130,9 +130,15 @@ class OAuth2Flow extends Flow {
// Start authorization flow to acquire an access token
$server= $request->param('state');
if (null === $stored || null === $server) {
- $state= bin2hex($this->rand->bytes(16));
- $session->register(self::SESSION_KEY, ['state' => $state, 'target' => (string)$uri]);
- $session->transmit($response);
+
+ // Reuse state
+ if (isset($stored['state'])) {
+ $state= $stored['state'];
+ } else {
+ $state= bin2hex($this->rand->bytes(16));
+ $session->register(self::SESSION_KEY, ['state' => $state, 'target' => (string)$uri]);
+ $session->transmit($response);
+ }
// Redirect the user to the authorization page
$params= [
from web-auth.
Fix released in https://github.com/xp-forge/web-auth/releases/tag/v3.4.1
from web-auth.
Related Issues (9)
- Undefined array key "token_type" HOT 3
- PHP 8.1 compatibility HOT 4
- Handle /?error=...
- JSON Web Token (JWT) Profile for OAuth 2.0 Client Authentication and Authorization Grants HOT 1
- OAuth 2.1
- Callback URL not approved for this client application HOT 4
- Access to authentication HOT 4
- Use authorization information from OAuth HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from web-auth.