PHP code example of polaris / social

1. Go to this page and download the library: Download polaris/social library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

polaris / social example snippets


use Polaris\Audit\AuditPlugin;
use Polaris\Social\SocialPlugin;

$polaris = Polaris::create(new Config(..., plugins: [
    new AuditPlugin(),
    new SocialPlugin(
        baseUrl: 'https://app.example.com/auth',
        providers: [
            'google' => ['client_id' => '...', 'client_secret' => '...'],
            'github' => ['client_id' => '...', 'client_secret' => '...'],
            'apple' => ['client_id' => 'com.example.app', 'team_id' => '...', 'key_id' => '...', 'private_key' => $pem],
            'microsoft' => ['client_id' => '...', 'client_secret' => '...', 'tenant' => 'common'],
        ],
        httpClient: $client, requestFactory: $requests, streamFactory: $streams,
        redirectUris: ['https://app.example.com/signed-in'],
    ),
]));

'acme' => ['client_id' => '...', 'client_secret' => '...', 'definition' => new Definition(
    'acme', 'Acme', 'https://acme.example/oauth/authorize', 'https://acme.example/oauth/token', 'https://acme.example/oauth/me',
    ['profile'], fn(array $me): Profile => new Profile((string) $me['id'], $me['email'], (bool) $me['verified'], $me['name']),
)],
'okta' => ['client_id' => '...', 'client_secret' => '...', 'issuer' => 'https://acme.okta.com'],   // OpenID Connect discovery

new SocialPlugin(
    baseUrl: 'https://app.example.com/auth',
    providers: [...],
    httpClient: $client, requestFactory: $requests, streamFactory: $streams,
    redirectUris: ['https://app.example.com/signed-in'],   // exact; the first is the default
    trustedProviders: ['google', 'apple'],                 // auto-link by verified email
    allowDifferentEmails: ['github'],                      // may link from a session with another email
    signUp: true,
    respectMfa: true,                                      // core's MFA gate applies to social sign-ins
    proxy: null,
);