[bug] Socialite::driver->with don't add parameters to redirect
gaetandezeiraud opened this issue · comments
Describe the bug
When I want to add pareameters with with
in a redirect()
. The parameters are not added to the generate URL.
Expected behavior
I set the following code (who is called correctly)
if ($provider == 'steam')
{
return Socialite::driver('steam')
->with(['response_type' => 'token', 'mobileminimal' => 1])->redirect();
}
But the response_type and mobileminimal parameters are not added to the generated URL.
Don't work as intended here https://docs.socialstream.dev/getting-started/customising-socialite#generating-redirect-urls
Tried with only response_type or only mobileminimal same problem.
Environment context
- Socialstream version: 4.1
- Jetstream stack: Inertia
- Laravel version: 10.10
- PHP version: 8.1
@Brouilles I've just ran a quick test in the project to make sure that this is working as intended:
it('generates a redirect using a custom callback', function (bool $manageRepos): void {
Config::set('services.github.manage_repos', $manageRepos);
Socialstream::generatesProvidersRedirectsUsing(
callback: fn () => new class() implements GeneratesProviderRedirect {
public function generate(string $provider): RedirectResponse
{
['provider' => $provider] = Route::current()->parameters();
$scopes = ['*'];
$scopes = match($provider) {
'github' => array_merge($scopes, [
'repos.manage',
]),
default => $scopes,
};
return Socialite::driver($provider)
->scopes($scopes)
->with(['response_type' => 'token', 'mobileminimal' => 1])
->redirect();
}
}
);
$response = $this->get(route('oauth.redirect', 'github'));
$response->assertRedirect()
->assertRedirectContains('github.com')
->assertRedirectContains('mobileminimal=1')
->assertRedirectContains('response_type=token');
if ($manageRepos) {
$response->assertRedirectContains('repos.manage');
}
})->with([
'manage repos' => [true],
'do not manage repos' => [false],
]);
Please can you confirm if this test case works for you?
I come back to you during the weekend.
What do you want me to do?
I thinking, maybe a problem for socialiteproviders only? Don't know.
Hi @Brouilles can you add the above test to your applications "feature" text suite and let me know if it runs correctly?
My bad, I don't have Github provider setup. I think it is why I have this error.
So here with this test:
public function test_redirect (bool $manageRepos = true): void {
Config::set('services.steam.manage_repos', $manageRepos);
Socialstream::generatesProvidersRedirectsUsing(
callback: fn () => new class() implements GeneratesProviderRedirect {
public function generate(string $provider): RedirectResponse
{
['provider' => $provider] = Route::current()->parameters();
$scopes = ['*'];
$scopes = match($provider) {
'steam' => array_merge($scopes, [
'repos.manage',
]),
default => $scopes,
};
return Socialite::driver($provider)
->scopes($scopes)
->with(['response_type' => 'token', 'mobileminimal' => 1])
->redirect();
}
}
);
$response = $this->get(route('oauth.redirect', 'steam'));
$response->assertRedirect()
->assertRedirectContains('steamcommunity.com')
->assertRedirectContains('mobileminimal=1')
->assertRedirectContains('response_type=token');
if ($manageRepos) {
$response->assertRedirectContains('repos.manage');
}
}
I have this error in the test
Tests\Feature\SocialstreamRegistrationTest > redirect
Redirect location [https://steamcommunity.com/openid/login?openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&openid.mode=checkid_setup&openid.return_to=http%3A%2F%2Fdezeiraud.test%2Foauth%2Fsteam%2Fcallback&openid.realm=http%3A%2F%2Fdezeiraud.test&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select] does not contain [mobileminimal=1].
Failed asserting that false is true.
@Brouilles The reason I asked you to implement the test with GitHub is because that is a 1st supported provider that I know 100% works.
If this doesn't work with a 3rd party provider, I suggest that the problem lies within that project - have you tried executing the following in Tinker on its own to determine if this works?
dd(Socialite::driver('steam')->scopes($scopes)->with(['response_type' => 'token', 'mobileminimal' => 1])->redirect());
Hello. Sorry for the Github test. So I setup & run it, the test works.
If this can help you, here the complet project. It is just a startup project with Steam setup.
@Brouilles This feels like more of an issue with the Socialstream Providers package, please can you try a fresh Laravel project with nothing but socialite & the steam socialite provider installed and a single route that redirects users from steam?
If you get the same issue, I'd suggest raising an issue with Socialstream Providers
Ok thank you.
I close the issue. I don't investigate more on my side. It is "just" for a side side project so don't have all this time to search more.