Skip to content

Commit b802eab

Browse files
authored
Merge pull request #2038 from willemverspyck/master
Add option "show_dialog" for Spotify resource owner
2 parents 3d42abc + 3a92453 commit b802eab

File tree

4 files changed

+61
-3
lines changed

4 files changed

+61
-3
lines changed

.github/workflows/ci.yaml

+7-3
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,15 @@ jobs:
8787
- php: '8.2'
8888
symfony-version: '^6.4'
8989
- php: '8.2'
90-
symfony-version: '^7.1'
90+
symfony-version: '^7.2'
9191
- php: '8.3'
9292
symfony-version: '^6.4'
9393
- php: '8.3'
94-
symfony-version: '^7.1'
94+
symfony-version: '^7.2'
95+
- php: '8.4'
96+
symfony-version: '^6.4'
97+
- php: '8.4'
98+
symfony-version: '^7.2'
9599
fail-fast: false
96100

97101
steps:
@@ -128,7 +132,7 @@ jobs:
128132
129133
- name: Upload test artifacts
130134
if: always()
131-
uses: actions/upload-artifact@v3
135+
uses: actions/upload-artifact@v4
132136
with:
133137
name: phpunit-logs-php${{ matrix.php }}
134138
path: build/logs/phpunit

docs/resource_owners/spotify.md

+15
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,21 @@ hwi_oauth:
1717
client_secret: <client_secret>
1818
```
1919
20+
Optionally you can force the user to approve the app again if they've already done so with the [`show_dialog`](https://developer.spotify.com/documentation/web-api/tutorials/code-flow) option:
21+
22+
```yaml
23+
# config/packages/hwi_oauth.yaml
24+
25+
hwi_oauth:
26+
resource_owners:
27+
any_name:
28+
type: spotify
29+
client_id: <client_id>
30+
client_secret: <client_secret>
31+
options:
32+
show_dialog: true # Can be false or true
33+
```
34+
2035
When you're done. Continue by configuring the security layer or go back to
2136
setup more resource owners.
2237

src/OAuth/ResourceOwner/SpotifyResourceOwner.php

+9
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ final class SpotifyResourceOwner extends GenericOAuth2ResourceOwner
3535
'profilepicture' => 'images.0.url',
3636
];
3737

38+
public function getAuthorizationUrl($redirectUri, array $extraParameters = [])
39+
{
40+
return parent::getAuthorizationUrl($redirectUri, array_merge(['show_dialog' => $this->options['show_dialog']], $extraParameters));
41+
}
42+
3843
/**
3944
* {@inheritdoc}
4045
*/
@@ -69,6 +74,10 @@ protected function configureOptions(OptionsResolver $resolver)
6974
'authorization_url' => 'https://accounts.spotify.com/authorize',
7075
'access_token_url' => 'https://accounts.spotify.com/api/token',
7176
'infos_url' => 'https://api.spotify.com/v1/me',
77+
'show_dialog' => null,
7278
]);
79+
80+
// @link https://developer.spotify.com/documentation/web-api/tutorials/code-flow
81+
$resolver->setAllowedValues('show_dialog', ['true', 'false', null]);
7382
}
7483
}

tests/OAuth/ResourceOwner/SpotifyResourceOwnerTest.php

+30
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,34 @@ public function testCustomResponseClass(): void
105105
$this->assertNull($userResponse->getRefreshToken());
106106
$this->assertNull($userResponse->getExpiresIn());
107107
}
108+
109+
public function testGetAuthorizationUrl(): void
110+
{
111+
$resourceOwner = $this->createResourceOwner();
112+
113+
$this->assertEquals(
114+
$this->options['authorization_url'].'&response_type=code&client_id=clientid&state=eyJzdGF0ZSI6InJhbmRvbSJ9&redirect_uri=http%3A%2F%2Fredirect.to%2F',
115+
$resourceOwner->getAuthorizationUrl('http://redirect.to/')
116+
);
117+
}
118+
119+
public function testGetAuthorizationUrlWithDialog(): void
120+
{
121+
$resourceOwner = $this->createResourceOwner(['show_dialog' => 'true']);
122+
123+
$this->assertEquals(
124+
$this->options['authorization_url'].'&response_type=code&client_id=clientid&state=eyJzdGF0ZSI6InJhbmRvbSJ9&redirect_uri=http%3A%2F%2Fredirect.to%2F&show_dialog=true',
125+
$resourceOwner->getAuthorizationUrl('http://redirect.to/')
126+
);
127+
}
128+
129+
public function testGetAuthorizationUrlWithoutDialog(): void
130+
{
131+
$resourceOwner = $this->createResourceOwner(['show_dialog' => 'false']);
132+
133+
$this->assertEquals(
134+
$this->options['authorization_url'].'&response_type=code&client_id=clientid&state=eyJzdGF0ZSI6InJhbmRvbSJ9&redirect_uri=http%3A%2F%2Fredirect.to%2F&show_dialog=false',
135+
$resourceOwner->getAuthorizationUrl('http://redirect.to/')
136+
);
137+
}
108138
}

0 commit comments

Comments
 (0)