Cleanup OAuth _noenv & enabled providers (#989)

This commit is contained in:
MartinOscar 2025-02-11 22:10:27 +01:00 committed by GitHub
parent a6963ad802
commit 35d25d216e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 9 additions and 22 deletions

View File

@ -31,8 +31,9 @@ final class DiscordProvider extends OAuthProvider
->content(new HtmlString('<p>Visit the <u><a href="https://discord.com/developers/applications" target="_blank">Discord Developer Portal</a></u> and click on <b>New Application</b>. Enter a <b>Name</b> (e.g. your panel name) and click on <b>Create</b>.</p><p>Copy the <b>Client ID</b> and the <b>Client Secret</b>, you will need them in the final step.</p>')), ->content(new HtmlString('<p>Visit the <u><a href="https://discord.com/developers/applications" target="_blank">Discord Developer Portal</a></u> and click on <b>New Application</b>. Enter a <b>Name</b> (e.g. your panel name) and click on <b>Create</b>.</p><p>Copy the <b>Client ID</b> and the <b>Client Secret</b>, you will need them in the final step.</p>')),
Placeholder::make('') Placeholder::make('')
->content(new HtmlString('<p>Under <b>Redirects</b> add the below URL.</p>')), ->content(new HtmlString('<p>Under <b>Redirects</b> add the below URL.</p>')),
TextInput::make('_noenv_redirect') TextInput::make('_noenv_callback')
->label('Redirect URL') ->label('Redirect URL')
->dehydrated()
->disabled() ->disabled()
->hintAction(fn () => request()->isSecure() ? CopyAction::make() : null) ->hintAction(fn () => request()->isSecure() ? CopyAction::make() : null)
->formatStateUsing(fn () => config('app.url') . (Str::endsWith(config('app.url'), '/') ? '' : '/') . 'auth/oauth/callback/discord'), ->formatStateUsing(fn () => config('app.url') . (Str::endsWith(config('app.url'), '/') ? '' : '/') . 'auth/oauth/callback/discord'),

View File

@ -25,6 +25,7 @@ final class GithubProvider extends OAuthProvider
->content(new HtmlString('<p>Visit the <u><a href="https://github.com/settings/developers" target="_blank">Github Developer Dashboard</a></u>, go to <b>OAuth Apps</b> and click on <b>New OAuth App</b>.</p><p>Enter an <b>Application name</b> (e.g. your panel name), set <b>Homepage URL</b> to your panel url and enter the below url as <b>Authorization callback URL</b>.</p>')), ->content(new HtmlString('<p>Visit the <u><a href="https://github.com/settings/developers" target="_blank">Github Developer Dashboard</a></u>, go to <b>OAuth Apps</b> and click on <b>New OAuth App</b>.</p><p>Enter an <b>Application name</b> (e.g. your panel name), set <b>Homepage URL</b> to your panel url and enter the below url as <b>Authorization callback URL</b>.</p>')),
TextInput::make('_noenv_callback') TextInput::make('_noenv_callback')
->label('Authorization callback URL') ->label('Authorization callback URL')
->dehydrated()
->disabled() ->disabled()
->hintAction(fn () => request()->isSecure() ? CopyAction::make() : null) ->hintAction(fn () => request()->isSecure() ? CopyAction::make() : null)
->default(fn () => config('app.url') . (Str::endsWith(config('app.url'), '/') ? '' : '/') . 'auth/oauth/callback/github'), ->default(fn () => config('app.url') . (Str::endsWith(config('app.url'), '/') ? '' : '/') . 'auth/oauth/callback/github'),

View File

@ -513,8 +513,6 @@ class Settings extends Page implements HasForms
"OAUTH_{$id}_ENABLED" => 'true', "OAUTH_{$id}_ENABLED" => 'true',
], $data); ], $data);
$data = array_filter($data, fn ($value) => !Str::startsWith($value, '_noenv'));
foreach ($data as $key => $value) { foreach ($data as $key => $value) {
$set($key, $value); $set($key, $value);
} }

View File

@ -61,6 +61,8 @@ class EditProfile extends BaseEditProfile
protected function getForms(): array protected function getForms(): array
{ {
$oauthProviders = collect(OAuthProvider::get())->filter(fn (OAuthProvider $provider) => $provider->isEnabled())->all();
return [ return [
'form' => $this->form( 'form' => $this->form(
$this->makeForm() $this->makeForm()
@ -122,24 +124,11 @@ class EditProfile extends BaseEditProfile
Tab::make(trans('profile.tabs.oauth')) Tab::make(trans('profile.tabs.oauth'))
->icon('tabler-brand-oauth') ->icon('tabler-brand-oauth')
->visible(function () { ->visible(count($oauthProviders) > 0)
$oauthProviders = OAuthProvider::get(); ->schema(function () use ($oauthProviders) {
foreach ($oauthProviders as $oauthProvider) {
if ($oauthProvider->isEnabled()) {
return true;
}
}
return false;
})
->schema(function () {
$actions = []; $actions = [];
$oauthProviders = OAuthProvider::get();
foreach ($oauthProviders as $oauthProvider) { foreach ($oauthProviders as $oauthProvider) {
if (!$oauthProvider->isEnabled()) {
continue;
}
$id = $oauthProvider->getId(); $id = $oauthProvider->getId();
$name = $oauthProvider->getName(); $name = $oauthProvider->getName();

View File

@ -58,11 +58,9 @@ class Login extends BaseLogin
{ {
$actions = []; $actions = [];
$oauthProviders = OAuthProvider::get(); $oauthProviders = collect(OAuthProvider::get())->filter(fn (OAuthProvider $provider) => $provider->isEnabled())->all();
foreach ($oauthProviders as $oauthProvider) { foreach ($oauthProviders as $oauthProvider) {
if (!$oauthProvider->isEnabled()) {
continue;
}
$id = $oauthProvider->getId(); $id = $oauthProvider->getId();