ワンクリックで
oidc-hosted-page-laravel
Implement "Sign in with SSO" in Laravel applications using SSOJet OIDC with Socialite.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
Implement "Sign in with SSO" in Laravel applications using SSOJet OIDC with Socialite.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
Implement Machine-to-Machine (M2M) authentication using SSOJet OAuth2 Client Credentials flow for backend services and daemons.
Implement "Sign in with SSO" in native Android/Kotlin applications using SSOJet OIDC with AppAuth.
Implement "Sign in with SSO" in Angular SPA applications using SSOJet OIDC with PKCE.
Implement "Sign in with SSO" in ASP.NET Core applications using SSOJet OIDC middleware.
Implement "Sign in with SSO" in Go applications using SSOJet OIDC Authorization Code flow.
Implement "Sign in with SSO" in native iOS/Swift applications using SSOJet OIDC with AppAuth.
SOC 職業分類に基づく
| name | oidc-hosted-page-laravel |
| description | Implement "Sign in with SSO" in Laravel applications using SSOJet OIDC with Socialite. |
This expert AI assistant guide walks you through integrating "Sign in with SSO" functionality into an existing login page in a Laravel application using SSOJet as an OIDC identity provider.
laravel/socialite.http://localhost:8000/auth/callback).composer require laravel/socialite
Add to your .env file:
SSOJET_ISSUER_URL=https://auth.ssojet.com
SSOJET_CLIENT_ID=your_client_id
SSOJET_CLIENT_SECRET=your_client_secret
SSOJET_REDIRECT_URI=http://localhost:8000/auth/callback
Add to config/services.php:
'ssojet' => [
'issuer_url' => env('SSOJET_ISSUER_URL'),
'client_id' => env('SSOJET_CLIENT_ID'),
'client_secret' => env('SSOJET_CLIENT_SECRET'),
'redirect' => env('SSOJET_REDIRECT_URI'),
],
<?php
// app/Providers/SSOJetProvider.php
namespace App\Providers;
use Laravel\Socialite\Two\AbstractProvider;
use Laravel\Socialite\Two\User;
class SSOJetProvider extends AbstractProvider
{
protected $scopes = ['openid', 'profile', 'email'];
protected $scopeSeparator = ' ';
protected function getAuthUrl($state)
{
return $this->buildAuthUrlFromBase(
config('services.ssojet.issuer_url') . '/oauth2/authorize', $state
);
}
protected function getTokenUrl()
{
return config('services.ssojet.issuer_url') . '/oauth2/token';
}
protected function getUserByToken($token)
{
$response = $this->getHttpClient()->get(
config('services.ssojet.issuer_url') . '/oauth2/userinfo',
['headers' => ['Authorization' => 'Bearer ' . $token]]
);
return json_decode($response->getBody(), true);
}
protected function mapUserToObject(array $user)
{
return (new User())->setRaw($user)->map([
'id' => $user['sub'] ?? null,
'name' => $user['name'] ?? null,
'email' => $user['email'] ?? null,
]);
}
}
Register in AppServiceProvider.php:
use Laravel\Socialite\Facades\Socialite;
use App\Providers\SSOJetProvider;
public function boot(): void
{
Socialite::extend('ssojet', function ($app) {
$config = $app['config']['services.ssojet'];
return new SSOJetProvider($app['request'], $config['client_id'], $config['client_secret'], $config['redirect']);
});
}
Modify resources/views/auth/login.blade.php:
<div class="login-container">
<h1>Sign In</h1>
<form id="loginForm" method="POST" action="{{ route('login') }}">
@csrf
<div>
<label for="email">Email</label>
<input type="email" id="email" name="email" required />
</div>
<div id="passwordField">
<label for="password">Password</label>
<input type="password" id="password" name="password" required />
</div>
<input type="hidden" id="isSSO" name="is_sso" value="false" />
<button type="submit" id="submitBtn">Sign In</button>
</form>
<button type="button" onclick="toggleSSO()">Sign in with SSO</button>
</div>
<script>
function toggleSSO() {
const f = document.getElementById('isSSO');
const p = document.getElementById('passwordField');
const b = document.getElementById('submitBtn');
if (f.value === 'false') {
f.value = 'true'; p.style.display = 'none';
document.getElementById('password').removeAttribute('required');
b.textContent = 'Continue with SSO';
} else {
f.value = 'false'; p.style.display = 'block';
document.getElementById('password').setAttribute('required','true');
b.textContent = 'Sign In';
}
}
</script>
SSO Controller (app/Http/Controllers/SSOController.php):
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Laravel\Socialite\Facades\Socialite;
use Illuminate\Support\Facades\Auth;
use App\Models\User;
class SSOController extends Controller
{
public function login(Request $request)
{
if ($request->input('is_sso') === 'true') {
return Socialite::driver('ssojet')
->with(['login_hint' => $request->input('email')])
->redirect();
}
// Existing password login logic
$credentials = $request->validate(['email' => 'required|email', 'password' => 'required']);
if (Auth::attempt($credentials)) {
$request->session()->regenerate();
return redirect('/dashboard');
}
return back()->withErrors(['email' => 'Invalid credentials.']);
}
public function callback(Request $request)
{
try {
$ssojetUser = Socialite::driver('ssojet')->user();
$user = User::updateOrCreate(
['email' => $ssojetUser->getEmail()],
['name' => $ssojetUser->getName(), 'ssojet_id' => $ssojetUser->getId()]
);
Auth::login($user);
return redirect('/dashboard');
} catch (\Exception $e) {
\Log::error('OIDC Callback Error: ' . $e->getMessage());
return redirect('/login')->withErrors(['sso' => 'SSO authentication failed.']);
}
}
}
Routes (routes/web.php):
use App\Http\Controllers\SSOController;
Route::get('/login', fn() => view('auth.login'))->name('login');
Route::post('/login', [SSOController::class, 'login']);
Route::get('/auth/callback', [SSOController::class, 'callback']);
php artisan serve.http://localhost:8000/login./dashboard..env to source control.ssojet_id column to the users table via migration.