main.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. $params = array_merge(
  3. require __DIR__ . '/../../common/config/params.php',
  4. require __DIR__ . '/../../common/config/params-local.php',
  5. require __DIR__ . '/params.php',
  6. require __DIR__ . '/params-local.php'
  7. );
  8. return [
  9. 'id' => 'oauth2',
  10. 'basePath' => dirname(__DIR__),
  11. 'controllerNamespace' => 'oauth2\controllers',
  12. 'bootstrap' => ['log'],
  13. 'modules' => [
  14. 'v1' => [ // 版本1
  15. 'class' => 'oauth2\modules\v1\Module',
  16. ],
  17. 'v2' => [ // 版本2
  18. 'class' => 'oauth2\modules\v2\Module',
  19. ],
  20. ],
  21. 'components' => [
  22. 'request' => [
  23. 'csrfParam' => '_csrf-oauth2',
  24. 'parsers' => [
  25. 'application/json' => 'yii\web\JsonParser',
  26. 'text/json' => 'yii\web\JsonParser',
  27. ]
  28. ],
  29. 'user' => [
  30. 'identityClass' => 'common\models\oauth2\AccessToken',
  31. 'identityCookie' => ['name' => '_identity-oauth2', 'httpOnly' => true],
  32. 'idParam' => '__oauth2',
  33. 'enableAutoLogin' => true,
  34. 'enableSession' => false,// 显示一个HTTP 403 错误而不是跳转到登录界面
  35. 'loginUrl' => null,
  36. ],
  37. 'session' => [
  38. // this is the name of the session cookie used for login on the oauth2
  39. 'name' => 'advanced-oauth2',
  40. 'timeout' => 86400,
  41. ],
  42. 'log' => [
  43. 'traceLevel' => YII_DEBUG ? 3 : 0,
  44. 'targets' => [
  45. [
  46. 'class' => 'yii\log\FileTarget',
  47. 'levels' => ['error', 'warning'],
  48. 'logFile' => '@runtime/logs/' . date('Y-m/d') . '.log',
  49. ],
  50. ],
  51. ],
  52. 'errorHandler' => [
  53. 'errorAction' => 'site/error',
  54. ],
  55. 'urlManager' => [
  56. 'class' => 'yii\web\UrlManager',
  57. // 美化Url,默认不启用。但实际使用中,特别是产品环境,一般都会启用。
  58. 'enablePrettyUrl' => true,
  59. // 是否启用严格解析,如启用严格解析,要求当前请求应至少匹配1个路由规则,
  60. // 否则认为是无效路由。
  61. // 这个选项仅在 enablePrettyUrl 启用后才有效。启用容易出错
  62. // 注意:如果不需要严格解析路由请直接删除或注释此行代码
  63. 'enableStrictParsing' => false,
  64. // 是否在URL中显示入口脚本。是对美化功能的进一步补充。
  65. 'showScriptName' => false,
  66. // 指定续接在URL后面的一个后缀,如 .html 之类的。仅在 enablePrettyUrl 启用时有效。
  67. 'suffix' => '',
  68. ],
  69. 'response' => [
  70. 'class' => 'yii\web\Response',
  71. 'as beforeSend' => 'api\behaviors\BeforeSend',
  72. ],
  73. ],
  74. 'as cors' => [
  75. 'class' => \yii\filters\Cors::class,
  76. ],
  77. 'params' => $params,
  78. ];
粤ICP备19079148号