Skip to content

Commit 7643f30

Browse files
committed
Remove deprecated support for instantiating OAuth flows w/o callback
1 parent 6bf29b7 commit 7643f30

6 files changed

Lines changed: 15 additions & 73 deletions

File tree

ChangeLog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ Web Authentication change log
55

66
## 7.0.0 / ????-??-??
77

8+
* **Heads up:** Removed support for deprecated constructor signature without
9+
callback in OAuth1 & OAuth2
10+
(@thekid)
811
* Changed `SessionBased` authentication to send 401 for sub-requests (e.g.
912
images, fetch(), ...), implementing feature suggested in #38
1013
(@thekid)

src/main/php/web/auth/oauth/OAuth1Flow.class.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class OAuth1Flow extends OAuthFlow {
1616
* @param web.auth.oauth.Credentials|(string|util.Secret)[] $consumer
1717
* @param string|util.URI $callback
1818
*/
19-
public function __construct($service, $consumer, $callback= null) {
19+
public function __construct($service, $consumer, $callback= '/') {
2020
$this->namespace= 'oauth1::flow';
2121
$this->service= rtrim($service, '/');
2222

@@ -29,13 +29,7 @@ public function __construct($service, $consumer, $callback= null) {
2929
$this->signature= new Signature(new BySecret(...$consumer));
3030
}
3131

32-
// BC: Support deprecated constructor signature without callback
33-
if (null === $callback) {
34-
trigger_error('Missing parameter $callback', E_USER_DEPRECATED);
35-
$this->callback= null;
36-
} else {
37-
$this->callback= $callback instanceof URI ? $callback : new URI($callback);
38-
}
32+
$this->callback= $callback instanceof URI ? $callback : new URI($callback);
3933
}
4034

4135
/**
@@ -90,9 +84,9 @@ public function authenticate($request, $response, $session) {
9084
)));
9185
}
9286

93-
// Enter authentication flow, resolving callback URI against the curren request.
87+
// Enter authentication flow, resolving callback URI against the current request.
9488
$uri= $this->url(true)->resolve($request);
95-
$callback= $this->callback ? $uri->resolve($this->callback) : $this->service($uri);
89+
$callback= $uri->resolve($this->callback);
9690

9791
// Check whether we are continuing an existing authentication flow based on the
9892
// state given by the server and our session; or if we need to start a new one.

src/main/php/web/auth/oauth/OAuth2Flow.class.php

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,15 @@ class OAuth2Flow extends OAuthFlow {
1919
* @param string|util.URI $callback
2020
* @param string[] $scopes
2121
*/
22-
public function __construct($auth, $tokens, $consumer, $callback= null, $scopes= ['user']) {
22+
public function __construct($auth, $tokens, $consumer, $callback= '/', $scopes= ['user']) {
2323
$this->namespace= 'oauth2::flow';
2424
$this->auth= $auth instanceof URI ? $auth : new URI($auth);
2525
$this->backend= $tokens instanceof OAuth2Endpoint
2626
? $tokens->using($consumer)
2727
: new OAuth2Endpoint($tokens, $consumer)
2828
;
29-
30-
// BC: Support deprecated constructor signature without callback
31-
if (is_array($callback) || null === $callback) {
32-
trigger_error('Missing parameter $callback', E_USER_DEPRECATED);
33-
$this->callback= null;
34-
$this->scopes= $callback ?? $scopes;
35-
} else {
36-
$this->callback= $callback instanceof URI ? $callback : new URI($callback);
37-
$this->scopes= $scopes;
38-
}
39-
29+
$this->callback= $callback instanceof URI ? $callback : new URI($callback);
30+
$this->scopes= $scopes;
4031
$this->rand= new Random();
4132
}
4233

@@ -87,9 +78,9 @@ public function authenticate($request, $response, $session) {
8778
return ByAccessToken::from($token);
8879
}
8980

90-
// Enter authentication flow, resolving callback URI against the curren request.
81+
// Enter authentication flow, resolving callback URI against the current request.
9182
$uri= $this->url(true)->resolve($request);
92-
$callback= $this->callback ? $uri->resolve($this->callback) : $this->service($uri);
83+
$callback= $uri->resolve($this->callback);
9384

9485
// Check whether we are continuing an existing authentication flow based on the
9586
// state given by the server and our session; or if we need to start a new one.

src/main/php/web/auth/oauth/OAuthFlow.class.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ protected function flow($state, $stored) {
1515
);
1616
}
1717

18-
/** @return ?util.URI */
18+
/** @return util.URI */
1919
public function callback() { return $this->callback; }
2020

21-
/** @param ?string|util.URI $callback */
21+
/** @param string|util.URI $callback */
2222
public function calling($callback): self {
23-
$this->callback= null === $callback || $callback instanceof URI ? $callback : new URI($callback);
23+
$this->callback= $callback instanceof URI ? $callback : new URI($callback);
2424
return $this;
2525
}
2626

src/test/php/web/auth/unittest/OAuth1FlowTest.class.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -164,22 +164,6 @@ public function replaces_fragment($fragment) {
164164
Assert::equals(['uri' => 'http://localhost/#'.$fragment, 'seed' => []], current($session->value(self::SNS)['flows']));
165165
}
166166

167-
/** @deprecated */
168-
#[Test, Values(from: 'paths')]
169-
public function deprecated_usage_without_callback_uri($path) {
170-
$request= ['oauth_token' => 'T'];
171-
$fixture= newinstance(OAuth1Flow::class, [self::AUTH, [self::ID, self::SECRET]], [
172-
'request' => function($path, $token= null, $params= []) use($request) { return $request; }
173-
]);
174-
\xp::gc();
175-
$session= (new ForTesting())->create();
176-
177-
Assert::equals(
178-
sprintf('%s/authenticate?oauth_token=T&oauth_callback=%s', self::AUTH, urlencode('http://localhost'.$path)),
179-
$this->redirectTo($this->authenticate($fixture, $path, $session))
180-
);
181-
}
182-
183167
#[Test]
184168
public function use_returned_client() {
185169
$flow= new OAuth1Flow(self::AUTH, [self::ID, self::SECRET], self::CALLBACK);

src/test/php/web/auth/unittest/OAuth2FlowTest.class.php

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -375,36 +375,6 @@ public function claims_returned_with_expiry() {
375375
);
376376
}
377377

378-
/** @deprecated */
379-
#[Test, Values(from: 'paths')]
380-
public function deprecated_usage_without_callback_uri($path) {
381-
$fixture= new OAuth2Flow(self::AUTH, self::TOKENS, self::CONSUMER);
382-
\xp::gc();
383-
384-
$session= (new ForTesting())->create();
385-
$this->assertLoginWith(
386-
'http://localhost'.$path,
387-
$fixture->scopes(),
388-
$this->authenticate($fixture, $path, $session),
389-
$session
390-
);
391-
}
392-
393-
/** @deprecated */
394-
#[Test, Values(from: 'paths')]
395-
public function deprecated_usage_with_scopes_in_place_of_callback_uri($path) {
396-
$fixture= new OAuth2Flow(self::AUTH, self::TOKENS, self::CONSUMER, ['user']);
397-
\xp::gc();
398-
399-
$session= (new ForTesting())->create();
400-
$this->assertLoginWith(
401-
'http://localhost'.$path,
402-
$fixture->scopes(),
403-
$this->authenticate($fixture, $path, $session),
404-
$session
405-
);
406-
}
407-
408378
#[Test]
409379
public function use_returned_client() {
410380
$flow= new OAuth2Flow(self::AUTH, self::TOKENS, self::CONSUMER, self::CALLBACK);

0 commit comments

Comments
 (0)