interworks/laravel-powerbi
Composer 安装命令:
composer require interworks/laravel-powerbi
包简介
A Laravel PowerBI REST API package
README 文档
README
A comprehensive Laravel package for interacting with the Microsoft Power BI REST API. Built on Saloon v4 with type-safe responses, automatic caching, and multiple OAuth2 authentication flows.
Features
- Multiple Authentication Flows: Service Principal, Admin Service Principal, and Azure User (authorization code)
- Type-Safe DTOs: Immutable response objects with full IDE autocomplete
- Automatic Caching: Configurable response caching via Saloon's cache plugin
- Account Type Restrictions: Automatic enforcement of API access restrictions
- Pagination Support: Automatic handling of continuation tokens
- Comprehensive API Coverage: Groups, Reports, Dashboards, Embed Tokens, and Admin endpoints
Requirements
- PHP 8.1+
- Laravel 9.x, 10.x, 11.x, or 12.x
- Microsoft Power BI Pro or Premium account
- Azure AD application with Power BI API permissions
Installation
composer require interworks/laravel-powerbi
Publish the configuration file:
php artisan vendor:publish --tag="laravel-powerbi-config"
Add your Power BI credentials to your .env file:
# Azure AD Configuration POWER_BI_TENANT=your-tenant-id # Cloud Environment (Optional) # One of: commercial (default), gcc, gcc_high, dod POWER_BI_CLOUD_ENVIRONMENT=commercial # Service Principal (Client Credentials) POWER_BI_CLIENT_ID=your-client-id POWER_BI_CLIENT_SECRET=your-client-secret # Admin Service Principal (Optional) POWER_BI_ADMIN_CLIENT_ID=your-admin-client-id POWER_BI_ADMIN_CLIENT_SECRET=your-admin-client-secret # Azure User OAuth Redirect (Optional) POWER_BI_REDIRECT_URI=https://your-app.com/auth/powerbi/callback # Caching Configuration POWER_BI_CACHE_ENABLED=true POWER_BI_CACHE_EXPIRY_SECONDS=3600
US Government Sovereign Clouds (GCC, GCC High, DoD)
Power BI tenants on Microsoft US Government licenses use different REST API and authentication
endpoints than the commercial cloud. Set POWER_BI_CLOUD_ENVIRONMENT (or pass cloudEnvironment
to any factory method / connector) to route requests to the correct endpoints:
| Environment | Power BI API base | Entra authority | Resource URL |
|---|---|---|---|
commercial |
api.powerbi.com |
login.microsoftonline.com |
analysis.windows.net/powerbi/api |
gcc |
api.powerbigov.us |
login.microsoftonline.com |
analysis.usgovcloudapi.net/powerbi/api |
gcc_high |
api.high.powerbigov.us |
login.microsoftonline.us |
high.analysis.usgovcloudapi.net/powerbi/api |
dod |
api.mil.powerbigov.us |
login.microsoftonline.us |
mil.analysis.usgovcloudapi.net/powerbi/api |
GCC authority: GCC (moderate) identities live in commercial Microsoft Entra, so
gccauthenticates againstlogin.microsoftonline.com(same as commercial) while still using thepowerbigov.usAPI host andusgovcloudapi.netresource. Only GCC High and DoD use the Azure Government authoritylogin.microsoftonline.us.
// Explicit per-connector override $connector = PowerBI::servicePrincipal( tenant: 'your-tenant-id', clientId: 'your-client-id', clientSecret: 'your-client-secret', cloudEnvironment: 'gcc' );
A missing or empty value defaults to commercial. Any other unrecognized value (e.g. a typo like
gcc-high) throws an InvalidArgumentException when the connector is created, so a sovereign-cloud
tenant can never be silently routed to the commercial endpoints.
Note: When using the Azure User flow with explicit OAuth scopes, make sure your scope strings reference the resource URL for your cloud environment (see the table above) rather than the commercial
analysis.windows.net/powerbi/apiresource.
Quick Start
use InterWorks\PowerBI\Facades\PowerBI; // Authenticate $token = PowerBI::getAccessToken(); PowerBI::authenticate($token); // Get groups and reports $groups = PowerBI::getGroups(); $reports = PowerBI::getReportsInGroup('group-id'); $report = PowerBI::getReportInGroup('group-id', 'report-id'); // Generate embed token use InterWorks\PowerBI\Requests\EmbedToken\ReportsGenerateTokenInGroup; $embedToken = PowerBI::send(new ReportsGenerateTokenInGroup( groupId: 'group-id', reportId: 'report-id', accessLevel: 'View' ));
Authentication
The package supports three authentication flows:
Service Principal (Client Credentials)
Best for backend automation and server-to-server communication.
$token = PowerBI::getAccessToken(); PowerBI::authenticate($token);
Restriction: Cannot access individual resource endpoints (/reports/{id}). Use group-scoped endpoints.
Admin Service Principal
For tenant-wide administration with elevated permissions.
$adminConnector = PowerBI::adminServicePrincipal(); PowerBI::setConnector($adminConnector);
Azure User (Authorization Code)
For user-delegated permissions with browser-based consent.
$connector = PowerBI::azureUser(redirectUri: 'https://your-app.com/callback'); $authUrl = $connector->getAuthorizationUrl(); // Redirect user, then exchange code for token
Available Endpoints
The package provides request classes for Power BI API endpoints:
Groups: GetGroups, GetGroupsAsAdmin
Reports: GetReportsInGroup, GetReportInGroup, GetReport
Dashboards: GetDashboardsInGroup, GetDashboardInGroup
Embed Tokens: ReportsGenerateTokenInGroup, DashboardsGenerateTokenInGroup
Admin: GetUserArtifactAccessAsAdmin
Browse all available requests in src/Requests.
Response DTOs
All responses are transformed into type-safe DTOs with readonly properties:
Collections: Groups, Reports, Dashboards, ArtifactAccessResponse
Resources: Group, Report, Dashboard, EmbedToken, ArtifactAccessEntry
$groups = PowerBI::getGroups(); // Laravel Collections with full IDE support $groups->groups->each(function ($group) { echo $group->name; // Fully typed properties });
Caching
Responses are automatically cached using Laravel's cache system:
POWER_BI_CACHE_ENABLED=true POWER_BI_CACHE_EXPIRY_SECONDS=3600
Check cache status:
if ($groups->response()->isCached()) { // Response served from cache }
Account Type Restrictions
Power BI API enforces different access levels by authentication type:
| Endpoint Type | Service Principal | Admin SP | Azure User |
|---|---|---|---|
Group-scoped (/groups/{id}/reports) |
✅ | ✅ | ✅ |
Individual (/reports/{id}) |
❌ | ✅ | ✅ |
Admin (/admin/*) |
❌ | ✅ | ❌ |
Restrictions are enforced automatically with clear exceptions.
Troubleshooting
Authentication failures: Verify Azure AD credentials and Power BI API permissions in your app registration.
Account type restrictions: Service Principal cannot access individual resource endpoints - use group-scoped endpoints or switch to Azure User.
Admin endpoint 401s: Ensure Service Principal has Power BI Administrator role assigned.
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for development setup and guidelines.
Changelog
Please see CHANGELOG.md for release history.
Security
Please review our security policy on how to report security vulnerabilities.
Credits
Built with Saloon v4.
License
The MIT License (MIT). Please see License File for more information.
interworks/laravel-powerbi 适用场景与选型建议
interworks/laravel-powerbi 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 831 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 12 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「InterWorks」 「laravel-powerbi」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 interworks/laravel-powerbi 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 interworks/laravel-powerbi 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 interworks/laravel-powerbi 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Alfabank REST API integration
Laravel package for Accurate Online API integration.
Shared RCX Laravel DataTables UI and configuration helpers.
Boot a Laravel project on any machine with one command: app:serve installs missing tools (PHP, Node, Composer, Herd, Docker), creates .env, sets up the database, runs migrations, builds assets, starts a queue worker and serves via Herd, Sail or artisan serve; app:down cleanly stops everything it sta
Branded, diagnostic error pages (500, 403, 404, 419, 503) for Filament — native Filament UI, dark mode and translations out of the box.
Turn any PDF into a Pingen-ready A4 letter (generated address cover page + A4 normalisation + safe margins) and send it through the Pingen print & mail API. Laravel-first.
统计信息
- 总下载量: 831
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-05