Overview
GB App integrates with Microsoft Power BI through the Power BI REST API. To enable this integration, you need to:- Register an Azure AD application
- Configure Power BI API permissions
- Set environment variables
- Test the connection
Azure AD App Registration
Sign in to Azure Portal
Navigate to Azure Portal and sign in with your organizational account.
Register New Application
- Go to Azure Active Directory > App registrations
- Click New registration
- Enter application details:
- Name: GB App Power BI Integration
- Supported account types: Accounts in this organizational directory only
- Redirect URI: Not required for service principal authentication
- Click Register
Note Application IDs
From the app overview page, copy:
- Application (client) ID - This is your
POWERBI_CLIENT_ID - Directory (tenant) ID - This is your tenant ID
Create Client Secret
- Go to Certificates & secrets
- Click New client secret
- Add description: “GB App Integration”
- Select expiration period (recommended: 24 months)
- Click Add
- Copy the secret value immediately - This is your
POWERBI_CLIENT_SECRET
Configure API Permissions
- Go to API permissions
- Click Add a permission
- Select Power BI Service
- Choose Delegated permissions or Application permissions
- Add these permissions:
Report.Read.AllDataset.Read.AllWorkspace.Read.All
- Click Add permissions
- Click Grant admin consent (requires admin privileges)
Power BI Service Principal Setup
Enable Service Principal in Power BI Admin
- Go to Power BI Admin Portal
- Navigate to Tenant settings
- Find Developer settings > Allow service principals to use Power BI APIs
- Enable for your organization or specific security groups
- Save changes
Authentication Methods
GB App supports two authentication methods:Method 1: Resource Owner Password Credentials (ROPC)
Used by default in the codebase:app/Traits/PowerBITrait.php
Method 2: Service Principal (Recommended for Production)
For production environments, use service principal authentication:Environment Configuration
Power BI Config File
config/power-bi.php
Environment Variables
Add these to your.env file:
.env
Configuration Parameters
- POWERBI_USER_ID: Optional user ID for tracking
- POWERBI_GRANT_TYPE: OAuth grant type (
passwordorclient_credentials) - POWERBI_CLIENT_SECRET: Azure AD app client secret
- POWERBI_CLIENT_ID: Azure AD app application ID
- POWERBI_RESOURCE: Power BI API resource URL
- POWERBI_USERNAME: Power BI Pro user account
- POWERBI_PASSWORD: User password
Testing the Connection
After configuration, clear cache and test:Test in Tinker
Test Import Reports
- Navigate to
/reports/import - Enter a workspace Group ID
- Click “Get Reports”
- If successful, you’ll see a list of reports from that workspace
Power BI API Endpoints
GB App uses these Power BI REST API endpoints:Authentication
Get Reports in Workspace
Generate Embed Token
Embed URL
Token Management
Access Token Lifecycle
Access tokens expire after 1 hour. GB App:- Generates access token on controller initialization
- Uses access token to generate embed tokens
- Stores embed tokens in database with expiration
- Automatically refreshes expired embed tokens
Embed Token Storage
Token Refresh Logic
app/Http/Controllers/ReportController.php
Checking Available Tokens
Power BI has limits on free embed tokens. Check your available tokens: Power BI Available Features APIWorkspace Group ID
To find your workspace Group ID:- Open Power BI workspace in browser
- Look at the URL:
- The GUID after
/groups/is your Group ID
Security Best Practices
Use Service Principal in Production
Avoid using user credentials in production. Use service principal authentication with client credentials grant.
Rotate Client Secrets Regularly
Set expiration dates for client secrets and rotate them before expiry.
Secure Environment Variables
Never commit
.env file. Use secret management in production:- Azure Key Vault
- AWS Secrets Manager
- HashiCorp Vault
Troubleshooting
401 Unauthorized when calling Power BI API
401 Unauthorized when calling Power BI API
403 Forbidden when accessing workspace
403 Forbidden when accessing workspace
- Add service principal or user to workspace with Member/Admin role
- Check workspace settings allow API access
- Verify workspace is in a Premium capacity (if required)
Token generation fails
Token generation fails
- Check that
POWERBI_GRANT_TYPEmatches your authentication method - Verify username and password are correct (for ROPC)
- Ensure client secret hasn’t expired
- Check network connectivity to Azure AD
Reports don't load in frontend
Reports don't load in frontend
- Check browser console for errors
- Verify embed token hasn’t expired
- Ensure Power BI JavaScript library is loaded
- Check that embedUrl is correctly formatted