Skip to content

Commit d0ae852

Browse files
Missing Jetstream/Socialstream code
1 parent 54b5631 commit d0ae852

File tree

4 files changed

+346
-0
lines changed

4 files changed

+346
-0
lines changed

config/fortify.php

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
<?php
2+
3+
use Laravel\Fortify\Features;
4+
5+
return [
6+
7+
/*
8+
|--------------------------------------------------------------------------
9+
| Fortify Guard
10+
|--------------------------------------------------------------------------
11+
|
12+
| Here you may specify which authentication guard Fortify will use while
13+
| authenticating users. This value should correspond with one of your
14+
| guards that is already present in your "auth" configuration file.
15+
|
16+
*/
17+
18+
'guard' => 'web',
19+
20+
/*
21+
|--------------------------------------------------------------------------
22+
| Fortify Password Broker
23+
|--------------------------------------------------------------------------
24+
|
25+
| Here you may specify which password broker Fortify can use when a user
26+
| is resetting their password. This configured value should match one
27+
| of your password brokers setup in your "auth" configuration file.
28+
|
29+
*/
30+
31+
'passwords' => 'users',
32+
33+
/*
34+
|--------------------------------------------------------------------------
35+
| Username / Email
36+
|--------------------------------------------------------------------------
37+
|
38+
| This value defines which model attribute should be considered as your
39+
| application's "username" field. Typically, this might be the email
40+
| address of the users but you are free to change this value here.
41+
|
42+
| Out of the box, Fortify expects forgot password and reset password
43+
| requests to have a field named 'email'. If the application uses
44+
| another name for the field you may define it below as needed.
45+
|
46+
*/
47+
48+
'username' => 'email',
49+
50+
'email' => 'email',
51+
52+
/*
53+
|--------------------------------------------------------------------------
54+
| Lowercase Usernames
55+
|--------------------------------------------------------------------------
56+
|
57+
| This value defines whether usernames should be lowercased before saving
58+
| them in the database, as some database system string fields are case
59+
| sensitive. You may disable this for your application if necessary.
60+
|
61+
*/
62+
63+
'lowercase_usernames' => true,
64+
65+
/*
66+
|--------------------------------------------------------------------------
67+
| Home Path
68+
|--------------------------------------------------------------------------
69+
|
70+
| Here you may configure the path where users will get redirected during
71+
| authentication or password reset when the operations are successful
72+
| and the user is authenticated. You are free to change this value.
73+
|
74+
*/
75+
76+
'home' => '/dashboard',
77+
78+
/*
79+
|--------------------------------------------------------------------------
80+
| Fortify Routes Prefix / Subdomain
81+
|--------------------------------------------------------------------------
82+
|
83+
| Here you may specify which prefix Fortify will assign to all the routes
84+
| that it registers with the application. If necessary, you may change
85+
| subdomain under which all of the Fortify routes will be available.
86+
|
87+
*/
88+
89+
'prefix' => '',
90+
91+
'domain' => null,
92+
93+
/*
94+
|--------------------------------------------------------------------------
95+
| Fortify Routes Middleware
96+
|--------------------------------------------------------------------------
97+
|
98+
| Here you may specify which middleware Fortify will assign to the routes
99+
| that it registers with the application. If necessary, you may change
100+
| these middleware but typically this provided default is preferred.
101+
|
102+
*/
103+
104+
'middleware' => ['web'],
105+
106+
/*
107+
|--------------------------------------------------------------------------
108+
| Rate Limiting
109+
|--------------------------------------------------------------------------
110+
|
111+
| By default, Fortify will throttle logins to five requests per minute for
112+
| every email and IP address combination. However, if you would like to
113+
| specify a custom rate limiter to call then you may specify it here.
114+
|
115+
*/
116+
117+
'limiters' => [
118+
'login' => 'login',
119+
'two-factor' => 'two-factor',
120+
],
121+
122+
/*
123+
|--------------------------------------------------------------------------
124+
| Register View Routes
125+
|--------------------------------------------------------------------------
126+
|
127+
| Here you may specify if the routes returning views should be disabled as
128+
| you may not need them when building your own application. This may be
129+
| especially true if you're writing a custom single-page application.
130+
|
131+
*/
132+
133+
'views' => true,
134+
135+
/*
136+
|--------------------------------------------------------------------------
137+
| Features
138+
|--------------------------------------------------------------------------
139+
|
140+
| Some of the Fortify features are optional. You may disable the features
141+
| by removing them from this array. You're free to only remove some of
142+
| these features or you can even remove all of these if you need to.
143+
|
144+
*/
145+
146+
'features' => [
147+
Features::registration(),
148+
Features::resetPasswords(),
149+
// Features::emailVerification(),
150+
Features::updateProfileInformation(),
151+
Features::updatePasswords(),
152+
Features::twoFactorAuthentication([
153+
'confirm' => true,
154+
'confirmPassword' => true,
155+
// 'window' => 0,
156+
]),
157+
],
158+
159+
];

config/jetstream.php

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
3+
use Laravel\Jetstream\Features;
4+
use Laravel\Jetstream\Http\Middleware\AuthenticateSession;
5+
6+
return [
7+
8+
/*
9+
|--------------------------------------------------------------------------
10+
| Jetstream Stack
11+
|--------------------------------------------------------------------------
12+
|
13+
| This configuration value informs Jetstream which "stack" you will be
14+
| using for your application. In general, this value is set for you
15+
| during installation and will not need to be changed after that.
16+
|
17+
*/
18+
19+
'stack' => 'inertia',
20+
21+
/*
22+
|--------------------------------------------------------------------------
23+
| Jetstream Route Middleware
24+
|--------------------------------------------------------------------------
25+
|
26+
| Here you may specify which middleware Jetstream will assign to the routes
27+
| that it registers with the application. When necessary, you may modify
28+
| these middleware; however, this default value is usually sufficient.
29+
|
30+
*/
31+
32+
'middleware' => ['web'],
33+
34+
'auth_session' => AuthenticateSession::class,
35+
36+
/*
37+
|--------------------------------------------------------------------------
38+
| Jetstream Guard
39+
|--------------------------------------------------------------------------
40+
|
41+
| Here you may specify the authentication guard Jetstream will use while
42+
| authenticating users. This value should correspond with one of your
43+
| guards that is already present in your "auth" configuration file.
44+
|
45+
*/
46+
47+
'guard' => 'sanctum',
48+
49+
/*
50+
|--------------------------------------------------------------------------
51+
| Features
52+
|--------------------------------------------------------------------------
53+
|
54+
| Some of Jetstream's features are optional. You may disable the features
55+
| by removing them from this array. You're free to only remove some of
56+
| these features or you can even remove all of these if you need to.
57+
|
58+
*/
59+
60+
'features' => [
61+
// Features::termsAndPrivacyPolicy(),
62+
// Features::profilePhotos(),
63+
// Features::api(),
64+
// Features::teams(['invitations' => true]),
65+
Features::accountDeletion(),
66+
],
67+
68+
/*
69+
|--------------------------------------------------------------------------
70+
| Profile Photo Disk
71+
|--------------------------------------------------------------------------
72+
|
73+
| This configuration value determines the default disk that will be used
74+
| when storing profile photos for your application's users. Typically
75+
| this will be the "public" disk but you may adjust this if needed.
76+
|
77+
*/
78+
79+
'profile_photo_disk' => 'public',
80+
81+
];

config/socialstream.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
use JoelButcher\Socialstream\Providers;
4+
5+
return [
6+
'middleware' => ['web'],
7+
'prompt' => 'Or Login Via',
8+
'providers' => [
9+
// Providers::github(),
10+
],
11+
'component' => 'socialstream::components.socialstream',
12+
];
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
3+
namespace tests;
4+
5+
use Illuminate\Foundation\Testing\RefreshDatabase;
6+
use Illuminate\Support\Facades\Session;
7+
use JoelButcher\Socialstream\Providers;
8+
use Laravel\Fortify\Features as FortifyFeatures;
9+
use Laravel\Socialite\Facades\Socialite;
10+
use Laravel\Socialite\Two\User;
11+
use Mockery;
12+
use Tests\TestCase;
13+
14+
class SocialstreamRegistrationTest extends TestCase
15+
{
16+
use RefreshDatabase;
17+
18+
/**
19+
* @dataProvider socialiteProvidersDataProvider
20+
*/
21+
public function test_users_get_redirected_correctly(string $provider): void
22+
{
23+
if (! Providers::enabled($provider)) {
24+
$this->markTestSkipped("Registration support with the $provider provider is not enabled.");
25+
}
26+
27+
config()->set("services.$provider", [
28+
'client_id' => 'client-id',
29+
'client_secret' => 'client-secret',
30+
'redirect' => "http://localhost/oauth/$provider/callback",
31+
]);
32+
33+
$response = $this->get("/oauth/$provider");
34+
$response->assertRedirectContains($provider);
35+
}
36+
37+
/**
38+
* @dataProvider socialiteProvidersDataProvider
39+
*/
40+
public function test_users_can_register_using_socialite_providers(string $socialiteProvider)
41+
{
42+
if (! FortifyFeatures::enabled(FortifyFeatures::registration())) {
43+
$this->markTestSkipped('Registration support is not enabled.');
44+
}
45+
46+
if (! Providers::enabled($socialiteProvider)) {
47+
$this->markTestSkipped("Registration support with the $socialiteProvider provider is not enabled.");
48+
}
49+
50+
$user = (new User())
51+
->map([
52+
'id' => 'abcdefgh',
53+
'nickname' => 'Jane',
54+
'name' => 'Jane Doe',
55+
'email' => 'janedoe@example.com',
56+
'avatar' => null,
57+
'avatar_original' => null,
58+
])
59+
->setToken('user-token')
60+
->setRefreshToken('refresh-token')
61+
->setExpiresIn(3600);
62+
63+
$provider = Mockery::mock('Laravel\\Socialite\\Two\\'.$socialiteProvider.'Provider');
64+
$provider->shouldReceive('user')->once()->andReturn($user);
65+
66+
Socialite::shouldReceive('driver')->once()->with($socialiteProvider)->andReturn($provider);
67+
68+
Session::put('socialstream.previous_url', route('register'));
69+
70+
$response = $this->get("/oauth/$socialiteProvider/callback");
71+
72+
$this->assertAuthenticated();
73+
$response->assertRedirect(route('dashboard', absolute: false));
74+
}
75+
76+
/**
77+
* @return array<int, array<int, string>>
78+
*/
79+
public static function socialiteProvidersDataProvider(): array
80+
{
81+
return [
82+
[Providers::bitbucket()],
83+
[Providers::facebook()],
84+
[Providers::github()],
85+
[Providers::gitlab()],
86+
[Providers::google()],
87+
[Providers::linkedin()],
88+
[Providers::linkedinOpenId()],
89+
[Providers::slack()],
90+
[Providers::twitterOAuth1()],
91+
[Providers::twitterOAuth2()],
92+
];
93+
}
94+
}

0 commit comments

Comments
 (0)