Download the PHP package bluefyn-international/aws-cognito without Composer

On this page you can find all versions of the php package bluefyn-international/aws-cognito. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package aws-cognito

Laravel Package to manage Web and API authentication with AWS Cognito

AWS Cognito package using the AWS SDK for PHP

This package is a fork of ellaisys/aws-cognito but has undergone major changes and is targeted towards newer version of both PHP and Laravel.

Latest Version on Packagist Release Date Total Downloads APM

This package provides a simple way to use AWS Cognito authentication in Laravel 8.x for Web and API Auth Drivers. The idea of this package, and some of the code, is based on the package from Pod-Point which you can find here: Pod-Point/laravel-cognito-auth, black-bits/laravel-cognito-auth and tymondesigns/jwt-auth.

We decided to use it and contribute it to the community as a package, that encourages standardised use and a RAD tool for authentication using AWS Cognito.

The following features are in the package:

Disclaimer

While this package is used in production it is not a GA (1.x) level release. Updates/changes will be coming which may cause issues. Additionally, not all features/options are fully implemented. You are invited to open Issues and PRs about the defects or new feature enhancements. However, this being a free support, we would not be able to commit to support SLAs or timelines.

Installation

Compatability

PHP Version Support
7.4 Yes
8.0 Untested
8.1 Untested
Laravel Version Support
7.x Untested
8.x Yes

Composer

You can install the package via composer.

Publishing Assets

You can publish the config and the view.

Last but not least you want to change the auth driver. To do so got to your config\auth.php file and change it to look the following:

Cognito User Pool

In order to use AWS Cognito as authentication provider, you require a Cognito User Pool.

If you haven't created one already, go to your Amazon management console and create a new user pool.

Next, generate an App Client. This will give you the App client id and the App client secret you need for your .env file.

IMPORTANT: Don't forget to activate the checkbox to Enable sign-in API for server-based Authentication. The Auth Flow is called: ADMIN_USER_PASSWORD_AUTH (formerly ADMIN_NO_SRP_AUTH)

You also need a new IAM Role with the following Access Rights:

From this user you can fetch the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY.

Cognito API configuration

Add the following fields to your .env file and set the values according to your AWS settings:

For more details on how to find AWS_COGNITO_CLIENT_ID, AWS_COGNITO_CLIENT_SECRET and AWS_COGNITO_USER_POOL_ID for your application, please refer COGNITOCONFIG File

Importing existing users into the Cognito Pool

If you are already working on an existing project and want to integrate Cognito you have to import a user csv file to your Cognito Pool.

Usage

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

In the simplest way you just go through your Auth Controllers and change namespaces from the traits which are currently implemented from Laravel.

You can change structure to suit your needs. Please be aware of the @extend statement in the blade file to fit into your project structure. At the current state you need to have those 4 form fields defined in here. Those are token, email, password, password_confirmation.

Single Sign-On

With our package and AWS Cognito we provide you a simple way to use Single Sign-Ons. For configuration options take a look at the config cognito.php.

When you want SSO enabled and a user tries to login into your application, the package checks if the user exists in your AWS Cognito pool. If the user exists, he will be created automatically in your database provided the add_missing_local_user_sso is to true, and is logged in simultaneously.

That's what we use the fields sso_user_model and cognito_user_fields for. In sso_user_model you define the class of your user model. In most cases this will simply be App\User.

With cognito_user_fields you can define the fields which should be stored in Cognito. Put attention here. If you define a field which you do not send with the Register Request this will throw you an InvalidUserFieldException and you won't be able to register.

Now that you have registered your users with their attributes in the AWS Cognito pool and your database and you want to attach a second app which should use the same pool. Well, that's actually pretty easy. You can use the API provisions that allows multiple projects to consume the same AWS Cognito pool.

*IMPORTANT: if your users table has a password field you are not going to need this anymore. What you want to do is set this field to be nullable, so that users can be created without passwords. From now on, Passwords are stored in Cognito.

Any additional registration data you have, for example firstname, lastname needs to be added in cognito.php cognito_user_fields config to be pushed to Cognito. Otherwise they are only stored locally and are not available if you want to use Single Sign On's.*

Middleware configuration for API Routes

In case you are using this library as API driver, you can register the middleware into the kernal.php in the $routeMiddleware

To use the middleware into the Web routes, you can use the std auth middleware as shown below

To use the middleware into the API routes, as shown below

Registering Users

As a default, if you are registering a new user with Cognito, Cognito will send you an email during signUp that includes the username and temporary password for the users to verify themselves.

Using this library in conjunction with AWS Lambda, once can look to customize the email template and content. The email template can be text or html based. The Lambda code for not included in this code repository. You can create your own. Any object (array) that you pass to the registration method is transferred as is to the lambda function, we are not prescriptive about the attribute names.

We have made is very easy for anyone to use the default behaviour.

  1. You don't need to create an extra field to store the verification token.
  2. You don't have to bother about the Sessions or API tokens, they are managed for you. The session or token is managed via the standard mechanism of Laravel. You have the liberty to keep it where ever you want, no security loop holes.
  3. If you use the trait provided by us 'BluefynInternational\Cognito\Auth\RegistersUsers', the code will be limited to just a few lines
  4. if you are using the Laravel scafolding, then make the password nullable in DB or drop it from schema. Passwords will be only managed by AWS Cognito.

  5. You don't need to turn off Cognito to send you emails. We rather propose the use of AWS Cognito or AWS SMS mailers, such that use credentials are always secure.

User Authentication

We have provided you with a useful trait that make the authentication very simple (with Web or API routes). You don't have to worry about any additional code to manage sessions and token (for API).

The trait takes in some additional parameters, refer below the function signature of the trait. Note that the function takes the object of Illuminate\Support\Collection instead of Illuminate\Http\Request. This will allow you to use this function in any tier of the code.

Also, the 'guard' name reference is passed, so that you can reuse the function for multiple guard drivers in your project. The function has the capability to handle the Session and Token Guards with multiple drivers and providers as defined in /config/auth.php

In case you want to use this trait for Web login, you can write the code as shown below in the AuthController.php

In case you want to use this trait for API based login, you can write the code as shown below in the AuthApiController.php

Delete User

If you want to give your users the ability to delete themselves from your app you can use our deleteUser function from the CognitoClient.

To delete the user you should call deleteUser and pass the email of the user as a parameter to it. After the user has been deleted in your cognito pool, delete your user from your database too.

We have implemented a new config option delete_user, which you can access through AWS_COGNITO_DELETE_USER env var. If you set this config to true, the user is deleted in the Cognito pool. If it is set to false, it will stay registered. Per default this option is set to false. If you want this behaviour you should set USE_SSO to true to let the user restore themselves after a successful login.

To access our CognitoClient you can simply pass it as a parameter to your Controller Action where you want to perform the deletion.

Laravel will take care of the dependency injection by itself.

Changelog

Please see CHANGELOG for more information on what has changed recently.

Security

If you discover any security related issues, please add it to the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.


All versions of aws-cognito with dependencies

PHP Build Version
Package Version
Requires php Version ^7.4|^8.0
guzzlehttp/guzzle Version >=6.0
aws/aws-sdk-php Version >=3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package bluefyn-international/aws-cognito contains the following files

Loading the files please wait ....