free2er/oauth-server-bundle

OAuth 服务器组件

1.0.0 2019-04-11 22:45 UTC

This package is auto-updated.

Last update: 2024-09-12 11:10:31 UTC


README

Symfony 组件,提供了 OAuth 2.0 授权服务器功能。授权服务器是通过使用 thephpleague/oauth2-server 库实现的。

安装

此组件可以通过 Composer 依赖管理器进行安装。

  1. 安装 Composer

  2. 将组件作为项目依赖项安装

     composer require free2er/oauth-server-bundle
    
  3. 启用组件

<?php

// config/bundles.php
return [
    // ...
    Free2er\OAuth\OAuthServerBundle::class => ['all' => true],
    // ...
];
  1. 配置组件参数
# config/packages/oauth_server.yaml
o_auth_server:
    encryption_key: '%env(resolve:APP_SECRET)%'
    private_key: file://%kernel.project_dir%/path/to/private.key
    private_key_password: ~ 
    ttl:
        access_token: PT1H
        authorization_code: PT1H
        refresh_token: P1M
    grants:
        - League\OAuth2\Server\Grant\ClientCredentialsGrant
        - League\OAuth2\Server\Grant\PasswordGrant
        - League\OAuth2\Server\Grant\AuthCodeGrant
        - League\OAuth2\Server\Grant\RefreshTokenGrant
  1. 配置路由
# config/routes.yaml
# ...
oauth:
    resource: '@OAuthServerBundle/Resources/config/routes.yaml'
    prefix: /auth
# ...
  1. 更新项目模式并注册客户端应用程序

     bin/console doctrine:schema:update
     bin/console oauth:client:update my-client -g client_credentials
    
  2. 完成!