An open API service indexing awesome lists of open source software.

https://github.com/dotkernel/dot-auth-social


https://github.com/dotkernel/dot-auth-social

Last synced: about 2 months ago
JSON representation

Awesome Lists containing this project

README

        

# dot-auth-social

Dotkernel's component used to authenticate users through Facebook and return credentials and user details.

> dot-auth-social is a wrapper on top of [thephpleague/oauth2-client](https://github.com/thephpleague/oauth2-client) social providers.

## Documentation

Documentation is available at: https://docs.dotkernel.org/dot-auth-social/.

## Badges

![OSS Lifecycle](https://img.shields.io/osslifecycle/dotkernel/dot-auth-social)
![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-auth-social/1.4.0)

[![GitHub issues](https://img.shields.io/github/issues/dotkernel/dot-auth-social)](https://github.com/dotkernel/dot-auth-social/issues)
[![GitHub forks](https://img.shields.io/github/forks/dotkernel/dot-auth-social)](https://github.com/dotkernel/dot-auth-social/network)
[![GitHub stars](https://img.shields.io/github/stars/dotkernel/dot-auth-social)](https://github.com/dotkernel/dot-auth-social/stargazers)
[![GitHub license](https://img.shields.io/github/license/dotkernel/dot-auth-social)](https://github.com/dotkernel/dot-auth-social/blob/1.0/LICENSE.md)

[![Build Static](https://github.com/dotkernel/dot-auth-social/actions/workflows/continuous-integration.yml/badge.svg?branch=1.0)](https://github.com/dotkernel/dot-auth-social/actions/workflows/continuous-integration.yml)
[![codecov](https://codecov.io/gh/dotkernel/dot-auth-social/graph/badge.svg?token=VIHN1HK8DR)](https://codecov.io/gh/dotkernel/dot-auth-social)
[![PHPStan](https://github.com/dotkernel/dot-auth-social/actions/workflows/static-analysis.yml/badge.svg?branch=1.0)](https://github.com/dotkernel/dot-auth-social/actions/workflows/static-analysis.yml)

## Requirements

- **PHP**: 8.1, 8.2, 8.3 or 8.4

## Installation

Run the following command in your project directory:

```shell
composer require dotkernel/dot-auth-social
```

After installing, add the `ConfigProvider` class to your configuration aggregate.

Create a new file `social-authentication.global.php` in `config/autoload` with the following contents:

```php
return [
'social_authentication' => [
'facebook' => [
'client_id' => '',
'client_secret' => '',
'redirect_uri' => '',
'graph_api_version' => '',
]
]
];
```

> Make sure to populate the array with your credentials.

## Usage

In this example we will create a new controller, but you can use an existing one too.

```php
service = $service;
}

public function authAction(): ResponseInterface
{
$code = $this->request->getQueryParams()['code'] ?? false;
if (! $code) {
return new RedirectResponse($this->service->getAuthorizationUrl());
}

$result = $this->service->authenticate($code);
if (! $result->isValid()) {
// invalid authentication, check $result->getMessages() for errors.
} else {
// valid authentication, use $result->getArrayCopy() to get the user details
}
}
}
```

Create a factory for the controller:

```php
get(FacebookService::class));
}
}
```

Make sure to register your controller with the factory in `ConfigProvider`.