بنقرة واحدة
oidc-hosted-page-php
Implement "Sign in with SSO" in vanilla PHP applications using SSOJet OIDC.
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
Implement "Sign in with SSO" in vanilla PHP applications using SSOJet OIDC.
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
استنادا إلى تصنيف SOC المهني
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.
| name | oidc-hosted-page-php |
| description | Implement "Sign in with SSO" in vanilla PHP applications using SSOJet OIDC. |
This expert AI assistant guide walks you through integrating "Sign in with SSO" functionality into an existing PHP application using SSOJet as an OIDC identity provider.
jumbojett/openid-connect-php.http://localhost:8000/callback.php).composer require jumbojett/openid-connect-php
Create a config.php file:
<?php
// config.php
return [
'issuer_url' => 'https://auth.ssojet.com',
'client_id' => 'your_client_id',
'client_secret' => 'your_client_secret',
'redirect_uri' => 'http://localhost:8000/callback.php',
];
Modify your login page (login.php):
<!-- login.php -->
<?php session_start(); ?>
<!DOCTYPE html>
<html>
<head><title>Sign In</title></head>
<body>
<div class="login-container">
<h1>Sign In</h1>
<?php if (isset($_GET['error'])): ?>
<p style="color: red;">Authentication failed. Please try again.</p>
<?php endif; ?>
<form id="loginForm" method="POST" action="auth.php">
<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>
</body>
</html>
1. Auth Handler (auth.php):
<?php
// auth.php
session_start();
require_once 'vendor/autoload.php';
use Jumbojett\OpenIDConnectClient;
$config = require 'config.php';
$isSSO = $_POST['is_sso'] ?? 'false';
$email = $_POST['email'] ?? '';
if ($isSSO === 'true') {
$oidc = new OpenIDConnectClient(
$config['issuer_url'],
$config['client_id'],
$config['client_secret']
);
$oidc->setRedirectURL($config['redirect_uri']);
$oidc->addScope(['openid', 'profile', 'email']);
// Store email for login_hint
$_SESSION['login_hint'] = $email;
$oidc->authenticate();
// The library handles the redirect automatically
} else {
// Existing password login logic here
error_log('Processing traditional login...');
header('Location: /dashboard.php');
exit;
}
2. Callback Handler (callback.php):
<?php
// callback.php
session_start();
require_once 'vendor/autoload.php';
use Jumbojett\OpenIDConnectClient;
$config = require 'config.php';
try {
$oidc = new OpenIDConnectClient(
$config['issuer_url'],
$config['client_id'],
$config['client_secret']
);
$oidc->setRedirectURL($config['redirect_uri']);
$oidc->addScope(['openid', 'profile', 'email']);
$oidc->authenticate();
// Get user info
$name = $oidc->requestUserInfo('name');
$email = $oidc->requestUserInfo('email');
$sub = $oidc->requestUserInfo('sub');
// TODO: Create a session for the user
$_SESSION['user'] = [
'sub' => $sub,
'name' => $name,
'email' => $email,
];
error_log('Authenticated User: ' . json_encode($_SESSION['user']));
header('Location: /dashboard.php');
exit;
} catch (Exception $e) {
error_log('OIDC Callback Error: ' . $e->getMessage());
header('Location: /login.php?error=oidc_failed');
exit;
}
php -S localhost:8000.http://localhost:8000/login.php./dashboard.php.php.ini.