承接 dotkernel/dot-auth-social 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

dotkernel/dot-auth-social

最新稳定版本:1.5.0

Composer 安装命令:

composer require dotkernel/dot-auth-social

包简介

Authentication wrapper for social providers

README 文档

README

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 social providers.

Documentation

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

Badges

OSS Lifecycle PHP from Packagist (specify version)

GitHub issues GitHub forks GitHub stars GitHub license

Build Static codecov PHPStan

Requirements

  • PHP: 8.2, 8.3, 8.4 or 8.5

Installation

Run the following command in your project directory:

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:

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

namespace Frontend\User\Controller;

use Dot\Controller\AbstractActionController;
use Dot\AuthSocial\Service\AuthenticationServiceInterface;
use Laminas\Diactoros\Response\RedirectResponse;
use Psr\Http\Message\ResponseInterface;

class FacebookController extends AbstractActionController
{
    private AuthenticationServiceInterface $service;

    public function __construct(AuthenticationServiceInterface $service)
    {
        $this->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

use Dot\AuthSocial\Service\FacebookService;
use Psr\Container\ContainerInterface;

class FacebookControllerFactory
{
    public function __invoke(ContainerInterface $container): FacebookController
    {
        return new FacebookController($container->get(FacebookService::class));
    }
}

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

统计信息

  • 总下载量: 1.23k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-11-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固