PHP code example of onetechasia / cognito

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

    

onetechasia / cognito example snippets


    'guards' => [
        'cognito-token' => [
            'driver' => 'cognito-token', // This line is important for using AWS Cognito as API Driver
            'provider' => 'users',
        ],
    ],

    protected $routeMiddleware = [
        'onetech.cognito' => \Onetech\Cognito\Http\Middleware\CognitoAuthenticate::class,
    ];

    use Onetech\Cognito\Auth\RegistersUsers;
    use Onetech\Cognito\Auth\AuthenticatesUsers;
    use Onetech\Cognito\Auth\RefreshToken;
    class UserController
    {
        use CognitoAuthenticatesUsers, RegistersUsers, RefreshToken;
    }

    //Registering user
    $bool = $this->createCognitoUser($request);
    //return boolean

    //Login user
    $check = $this->attemptLogin($request);
    //Response using AccessToken for call API
    //Response using RefreshToken to fetch new AccessToken
    //Response using IdToken to get user information

    //Fetch new AccessToken and IdToken
    $response = $this->refreshCoginitoToken($request);
    //Same API login

    $check = $this->setUserPassword($request);

    $accessToken = Auth::guard('cognito-token')->getTokenForRequest();
    $oldPassword = $request->old_password;
    $newPassword = $request->new_password;
    $check = $this->changeUserPassword($accessToken, $oldPassword, $newPassword);

    $userInfo = Auth::guard('cognito-token')->user();

    $accessToken = Auth::guard('cognito-token')->getTokenForRequest();
    $check = $this->signOut($accessToken);
bash
    php artisan vendor:publish --provider="Onetech\Cognito\Providers\CognitoServiceProvider"