auth0-samples/laravel
Composer 安装命令:
composer create-project auth0-samples/laravel
包简介
Sample application demonstrating how to integrate Auth0 with Laravel 9 or Laravel 10 for session-based authentication and token-based authorization.
关键字:
README 文档
README
📚 Documentation — :rocket: Getting Started — :round_pushpin: Routes — :wrench: Default Changes
This is a sample project demonstrating how to integrate the Auth0 Laravel SDK into a Laravel 9 application. For Laravel 10 applications, the integration steps are identical.
Documentation
Guidance on integrating Auth0 into your Laravel application can be found here:
- Auth0 Laravel SDK Readme
- Auth0 Laravel SDK Session Authentication Quickstart
- Auth0 Laravel SDK Token Authorization Quickstart
You may also find the following documentation from the SDK's GitHub repository useful:
Getting Started
Use Composer's create-project command to clone this repository and install the dependencies:
composer create-project auth0-samples/laravel auth0-laravel-quickstart && cd auth0-laravel-quickstart
Authenticate with Auth0 using the bundled Auth0 CLI:
./auth0 login
Note
Authenticate as a "user" if prompted.
Create an Auth0 Application:
./auth0 apps create \ --name "My Laravel Backend" \ --type "regular" \ --auth-method "post" \ --callbacks "http://localhost:8000/callback" \ --logout-urls "http://localhost:8000" \ --reveal-secrets \ --no-input \ --json > .auth0.app.json
Create an Auth0 API:
./auth0 apis create \ --name "My Laravel Backend API" \ --identifier "https://github.com/auth0/laravel-auth0" \ --offline-access \ --no-input \ --json > .auth0.api.json
Run the application:
php artisan serve
Demonstration Routes
This sample includes a few demonstration routes to help you get started.
Session-Based Authentication
The SDK automatically registers the following routes for session-based authentication:
| Method | Route | Description |
|---|---|---|
| GET | /login | Starts the user authentication flow. Sets up some initial cookies, and redirects to Auth0 to authenticate. |
| GET | /callback | Handles the return callback from Auth0. Completes setting up the user's Laravel session. |
| GET | /logout | Logs the user out. |
The routes/web.php file contains routes that demonstrate working with session-based authentication. These are:
| Method | Route | Description |
|---|---|---|
| GET | /private | Demonstrates how to protect a route with the auth middleware. |
| GET | /scope | Demonstrates how to protect a route with the can middleware. |
| GET | /colors | Demonstrates how to make Management API calls. |
Token-Based Authorization
The routes/api.php file contains routes that demonstrate token-based authorization. These are:
| Method | Route | Description |
|---|---|---|
| GET | /api | Demonstrates how to extract information from the request token. |
| GET | /api/private | Demonstrates how to protect an API route with the auth middleware. |
| GET | /api/scope | Demonstrates how to protect an API route with the can middleware. |
| GET | /api/me | Demonstrates how to make Management API calls. |
Changes to the Default Laravel Application
This sample is based on the default Laravel application you can create using laravel new or composer create-project.
Note
For Laravel 10, usecomposer create-project laravel/laravel:^10.0and follow the same steps outlined below.
Few changes are necessary to get started, as the SDK automatically sets up all the necessary guards, middleware and other services necessary to support authentication and authorization. The following is a list of changes that have been applied:
-
The
auth0/loginpackage has been added to thecomposer.jsonfile, using:composer require auth0/login:^7.8 --update-with-all-dependencies
-
The
config/auth0.phpfile was generated, using:php artisan vendor:publish --tag auth0
-
The
routes/web.phpfile was updated to include the demonstration routes. -
The
routes/api.phpfile was updated to include the demonstration routes.
Feedback
We appreciate your feedback! Please create an issue in this repository or reach out to us on Community.
Vulnerability Reporting
Please do not report security vulnerabilities on the public GitHub issue tracker. The Responsible Disclosure Program details the procedure for disclosing security issues.
What is Auth0?
Auth0 helps you to easily:
- implement authentication with multiple identity providers, including social (e.g., Google, Facebook, Microsoft, LinkedIn, GitHub, Twitter, etc), or enterprise (e.g., Windows Azure AD, Google Apps, Active Directory, ADFS, SAML, etc.)
- log in users with username/password databases, passwordless, or multi-factor authentication
- link multiple user accounts together
- generate signed JSON Web Tokens to authorize your API calls and flow the user identity securely
- access demographics and analytics detailing how, when, and where users are logging in
- enrich user profiles from other data sources using customizable JavaScript rules
License
This project is licensed under the MIT license. See the LICENSE file for more info.
auth0-samples/laravel 适用场景与选型建议
auth0-samples/laravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 479 次下载、GitHub Stars 达 46, 最近一次更新时间为 2023 年 05 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「framework」 「authorization」 「api」 「OpenId」 「Authentication」 「oauth」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 auth0-samples/laravel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 auth0-samples/laravel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 auth0-samples/laravel 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP Framework HLEB2 is the foundation of the web application. Provides ease of development and application performance.
Ory-Hydra OAuth 2.0 Client Provider for The PHP League OAuth2-Client
A lightweight and powerful OAuth 2.0 authorization and resource server library with support for all the core specification grants. This library will allow you to secure your API with OAuth and allow your applications users to approve apps that want to access their data from your API.
A PSR-7 compatible library for making CRUD API endpoints
Laravel JWT auth service package
Zoho OAuth 2.0 Client Provider for The PHP League OAuth2-Client
统计信息
- 总下载量: 479
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 46
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-05-20