PHPackages                             onetechasia/cognito - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. onetechasia/cognito

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

onetechasia/cognito
===================

User manage / login / register / forgot password with aws cognito

v0.0.3(3y ago)06MITPHPPHP ^8.1

Since Apr 27Pushed 3y ago1 watchersCompare

[ Source](https://github.com/phuocduy1988/onetech-cognito)[ Packagist](https://packagist.org/packages/onetechasia/cognito)[ RSS](/packages/onetechasia-cognito/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (3)Versions (4)Used By (0)

Installation
------------

[](#installation)

You can install the package via composer.

```
composer require onetechasia/cognito
```

Next you can publish the config

```
    php artisan vendor:publish --provider="Onetech\Cognito\Providers\CognitoServiceProvider"
```

Configure
---------

[](#configure)

Add config to environment file: .env

```
# AWS Cognito configurations
AWS_ACCESS_KEY_ID=""
AWS_SECRET_ACCESS_KEY=""
AWS_COGNITO_CLIENT_ID=""
AWS_COGNITO_CLIENT_SECRET=""
AWS_COGNITO_USER_POOL_ID=""
AWS_COGNITO_REGION="us-east-1"
AWS_COGNITO_VERSION="latest"
```

Last but not least you want to change the auth driver: config/auth.php

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

Add to middleware for authentication: app/Http/Kernel.php

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

Usage
-----

[](#usage)

Our package is providing you these traits you can just add to your Auth Controllers to get our package running.

- Onetech\\Cognito\\Auth\\AuthenticatesUsers
- Onetech\\Cognito\\Auth\\RegistersUsers
- Onetech\\Cognito\\Auth\\RefreshToken

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

Using in code.

1. Registering to cognito:

Payload: username = email or custom username, password belong to policy of cognito need validation

```
    {
        "name": "Le Duy",
        "username": "duy@onetech.vn",
        "email": "duy@onetech.vn",
        "password": "123456",
        "any attributes": "add more if needed"
    }
```

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

2. Login cognito

Payload: username and password is required

```
    {
      "username": "duy@onetech.vn",
      "password": "password",
      "remember": true
    }
```

```
    //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
```

3. Fetch new token

Payload: username and refresh\_token is required

```
    {
      "username": "duy@onetech.vn",
      "refresh_token": "refresh token"
    }
```

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

4. Set user password use for reset password

Payload: username and refresh\_token is required

```
    {
      "username": "duy@onetech.vn",
      "password": "password"
    }
```

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

4. Change user password

API call need add header. Authorization: Bearer AccessToken

Payload: old\_password and new\_password is required

```
    {
      "old_password": "old password",
      "new_password": "new password"
    }
```

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

5. Get User Info

You can using IdToken parse user info or call api to get information

API call need add header. Authorization: Bearer AccessToken

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

6. Sign out user

API call need add header. Authorization: Bearer AccessToken

```
    $accessToken = Auth::guard('cognito-token')->getTokenForRequest();
    $check = $this->signOut($accessToken);
```

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

3

Last Release

1111d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/135f77e04bc988eef34a166451c61aa59a16f300328d13408ce72a54cf7d00f2?d=identicon)[phuocduy1988](/maintainers/phuocduy1988)

---

Top Contributors

[![phuocduy1988](https://avatars.githubusercontent.com/u/15603240?v=4)](https://github.com/phuocduy1988 "phuocduy1988 (6 commits)")

---

Tags

phplaravelawsauthAuthenticationoauthCognitouser poolonetech

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/onetechasia-cognito/health.svg)

```
[![Health](https://phpackages.com/badges/onetechasia-cognito/health.svg)](https://phpackages.com/packages/onetechasia-cognito)
```

###  Alternatives

[ellaisys/aws-cognito

AWS Cognito package that allows Auth and other related features using the AWS SDK for PHP

120220.7k1](/packages/ellaisys-aws-cognito)[auth0/login

Auth0 Laravel SDK. Straight-forward and tested methods for implementing authentication, and accessing Auth0's Management API endpoints.

2745.0M3](/packages/auth0-login)[pmill/aws-cognito

A PHP client for AWS Cognito user pools

74266.0k3](/packages/pmill-aws-cognito)[pallant/laravel-aws-cognito-auth

An authentication driver for Laravel for authenticating users in AWS Cognito User Pools

777.7k](/packages/pallant-laravel-aws-cognito-auth)[kinde-oss/kinde-auth-php

Kinde PHP SDK for authentication

2369.5k3](/packages/kinde-oss-kinde-auth-php)[benbjurstrom/cognito-jwt-guard

A laravel auth guard for JSON Web Tokens issued by Amazon AWS Cognito

1113.1k](/packages/benbjurstrom-cognito-jwt-guard)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
