Skip to content

Commit 14f8dd2

Browse files
committedSep 13, 2023
Add option to controls whether a user should be created or not when a new user is logging in through Oauth
1 parent 135c105 commit 14f8dd2

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed
 

‎config/oauth.php

+11
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@
1515
*/
1616
'providers' => ['google'],
1717

18+
/*
19+
|--------------------------------------------------------------------------
20+
| This boolean controls whether a user should be created or not
21+
| when a new user is logging in through Oauth
22+
|--------------------------------------------------------------------------
23+
|
24+
| Possible values: true, false
25+
|
26+
*/
27+
'create_user_with_default_role' => true,
28+
1829
/*
1930
|--------------------------------------------------------------------------
2031
| New user default role name (legacy)

‎src/Http/Controllers/Admin/LoginController.php

+6
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,12 @@ public function handleProviderCallback($provider, OauthRequest $request)
240240
return $this->afterAuthentication($request, $user);
241241
}
242242
} else {
243+
if (!config('twill.oauth.create_user_with_default_role', true)) {
244+
return $this->redirector->to(route('twill.login'))->withErrors([
245+
'error' => __('auth.failed'),
246+
]);
247+
}
248+
243249
// If the user doesn't exist, create it
244250
$user = $repository->oauthCreateUser($oauthUser);
245251
$user->linkProvider($oauthUser, $provider);

0 commit comments

Comments
 (0)
Please sign in to comment.