PHP code example of socialiteproviders / imis

1. Go to this page and download the library: Download socialiteproviders/imis 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/ */

    

socialiteproviders / imis example snippets


'imis' => [
    'host' => env('IMIS_HOST'),
    'login_url' => env('IMIS_LOGIN_URL'),
    'client_id' => env('IMIS_CLIENT_ID'),
    'client_secret' => env('IMIS_CLIENT_SECRET'),
    'redirect' => env('IMIS_CALLBACK_URL'),
],

Event::listen(function (\SocialiteProviders\Manager\SocialiteWasCalled $event) {
    $event->extendSocialite('imis', \SocialiteProviders\Imis\Provider::class);
});

protected $listen = [
    \SocialiteProviders\Manager\SocialiteWasCalled::class => [
        // ... other providers
        \SocialiteProviders\Imis\ImisExtendSocialite::class.'@handle',
    ],
];

return Socialite::driver('imis')->redirect();

IMIS_HOST=https://www.public-imis-site.com
IMIS_LOGIN_URL=Web/Sign-in.aspx
IMIS_CLIENT_ID=MySSOApp
IMIS_CLIENT_SECRET=
IMIS_CALLBACK_URL=https://example-laravel-site.com/oauth2/imis/callback

    // -- When handling a POST to the callback url
    
        public function oauthHandleCallback(Request $request, String $provider): RedirectResponse
        {
            switch ($provider) {
            
                case "imis":
    
                        // Copy 'refresh_token' to a 'code' for use in Socialite
                        $request->request->add(['code' => $request->post('refresh_token')]);
    
                        // Fails if user is a guest
                        try {
                            $user = Socialite::driver('imis')->stateless()->user();
                        }
                        catch(\Throwable $e) {
                            // Redirect to Imis login
                            return redirect()->away(config('services.imis.host').'/'.config('services.imis.login_url'));
                        }
                    break;
    
                default:
                    dd('provider fail not found');
            }
    
            $authUser = $this->findOrCreateUser($user, $provider);
    
            Auth::login($authUser, true);
    
            return redirect(config('app.url').'/member');
        }