PHP code example of rs / auth-onekey

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

    

rs / auth-onekey example snippets


//.env

ONE_KEY_DEBUG=<boolean>
ONE_KEY_LIVE=<boolean>

//web.php

Route::get('onekey/callback', [OneKeyLoginController::class, 'handleProviderCallback']);

//Http\Controllers\OneKeyLoginController.php

use RedSnapper\OneKey\OneKeyProvider;

//..//

public function handleProviderCallback(OneKeyProvider $provider)
{   // Get OneKey user from the provider
    $providerUser = $provider->user();
    
    //Map the one-key user with your User model, save in DB
    // or perform any other action
    $user = new User([
        'id' => $providerUser->getId(),
        'name' => $providerUser->getFullName(),
        'email' => $providerUser->getEmail(),
        'guard' => 'web'
    ]);
    
    session()->put($user->guard, $user->toArray());
    auth($user->guard)->login($user);

    return redirect()->intended();
}

$user = $provider->user();

$user->getId(); //?string 
$user->getEmail(); //?string 
$user->getFirstName(); //?string 
$user->getLastName(); //?string 
$user->getFullName(); //?string 
$user->getCity(); //?string 
$user->getProfession(); //?string 
$user->getPhone(); //?string
$user->isHCP(); //bool
$user->trustLevel(); //int

$user->getRaw(); //array
bash
php artisan vendor:publish --tag=onekey-config