This skill should be used when the user asks to "set up authentication", "add login", "add logout", "configure Entra ID", "set up Azure AD auth", "add Microsoft login", "enable authentication", "set up sign in", "add role-based access", "add authorization", "protect routes", "add auth to my site", "configure identity provider", or wants to set up authentication (login/logout via Microsoft Entra ID) and role-based authorization for their Power Pages code site.
Install with Tessl CLI
npx tessl i github:microsoft/power-platform-skills --skill setup-auth87
Quality
87%
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Configure authentication (login/logout via Microsoft Entra ID) and role-based authorization for a Power Pages code site. This skill creates an auth service, type declarations, authorization utilities, auth UI components, and role-based access control patterns appropriate to the site's framework.
Initial request: $ARGUMENTS
Prerequisites:
- An existing Power Pages code site created via
/power-pages:create-site- The site must be deployed at least once (
.powerpages-sitefolder must exist)- Web roles must be created via
/power-pages:create-webroles
Goal: Confirm the project exists, identify the framework, verify deployment status and web roles, and check for existing auth code.
Look for powerpages.config.json in the current directory or immediate subdirectories:
**/powerpages.config.jsonIf not found: Tell the user to create a site first with /power-pages:create-site.
Read package.json to determine the framework (React, Vue, Angular, or Astro). See ${CLAUDE_PLUGIN_ROOT}/references/framework-conventions.md for the full framework detection mapping.
Look for the .powerpages-site folder:
**/.powerpages-siteIf not found: Tell the user the site must be deployed first:
"The
.powerpages-sitefolder was not found. The site needs to be deployed at least once before authentication can be configured."
Use AskUserQuestion:
| Question | Options |
|---|---|
| Your site needs to be deployed first. Would you like to deploy now? | Yes, deploy now (Recommended), No, I'll do it later |
If "Yes, deploy now": Invoke /power-pages:deploy-site, then resume.
If "No": Stop — the site must be deployed first.
Look for web role YAML files in .powerpages-site/web-roles/:
**/.powerpages-site/web-roles/*.ymlRead each file and compile a list of existing web roles (name, id, flags).
If no web roles exist: Warn the user that web roles are needed for authorization. Ask if they want to create them first:
| Question | Options |
|---|---|
| No web roles were found. Web roles are required for role-based authorization. Would you like to create them now? | Yes, create web roles first (Recommended), Skip — I'll add roles later |
If "Yes": Invoke /power-pages:create-webroles, then resume.
If "Skip": Continue — auth service and login/logout will still work, but role-based authorization will need roles created later.
Search for existing auth files to avoid duplicating work:
src/services/authService.ts or src/services/authService.jssrc/types/powerPages.d.tssrc/utils/authorization.ts or src/utils/authorization.jsAuthButton.tsx, AuthButton.vue)If auth files already exist, present them to the user and ask whether to overwrite or skip.
Goal: Gather authentication requirements from the user and present the implementation plan for approval.
Use AskUserQuestion to determine the scope:
| Question | Options |
|---|---|
| Which authentication features do you need? | Login & Logout + Role-based access control (Recommended), Login & Logout only, Role-based access control only (auth service already exists) |
If web roles were found in Phase 1.4, also ask:
| Question | Options |
|---|---|
| Which web roles should have access to protected areas of the site? | (List discovered web role names as options) |
Present the implementation plan inline:
Authentication/Registration/ProfileRedirectEnabled = false)Use AskUserQuestion to get approval:
| Question | Options |
|---|---|
| Here is the implementation plan for authentication and authorization. Would you like to proceed? | Approve and proceed (Recommended), I'd like to make changes |
If "Approve and proceed": Continue to Phase 3.
If "I'd like to make changes": Ask the user what they want to change, revise the plan, and present it again for approval.
Goal: Create the authentication service, type declarations, and framework-specific auth hook/composable with local development mock support.
Reference: ${CLAUDE_PLUGIN_ROOT}/skills/setup-auth/references/authentication-reference.md
Create src/types/powerPages.d.ts with type definitions for the Power Pages portal object and user:
PowerPagesUser interface — userName, firstName, lastName, email, contactId, userRoles[]PowerPagesPortal interface — User, version, type, id, geo, tenant, etc.Window interface extension for Microsoft.Dynamic365.PortalCreate the auth service file based on the detected framework:
All frameworks: Create src/services/authService.ts with these functions:
getCurrentUser() — reads from window.Microsoft.Dynamic365.Portal.UserisAuthenticated() — checks if user exists and has userNamegetTenantId() — reads from portal config (window.Microsoft.Dynamic365.Portal.tenant)fetchAntiForgeryToken() — fetches from /_layout/tokenhtml and parses HTML responselogin(returnUrl?) — creates a form POST to /Account/Login/ExternalLogin with:
/_layout/tokenhtmlhttps://login.windows.net/{tenantId}/logout(returnUrl?) — redirects to /Account/Login/LogOffgetUserDisplayName() — prefers full name, falls back to userNamegetUserInitials() — for avatar displayCRITICAL: Power Pages authentication is server-side (session cookies). The login flow posts a form to the server which redirects to Entra ID. There is no client-side token management. The fetchAntiForgeryToken() call gets a CSRF token for the form POST, not a bearer token.
Based on the detected framework:
src/hooks/useAuth.ts — custom hook returning { user, isAuthenticated, isLoading, displayName, initials, login, logout, refresh }src/composables/useAuth.ts — composable using ref, computed, onMounted returning reactive auth statesrc/app/services/auth.service.ts — injectable service with BehaviorSubject for user statesrc/services/authService.ts only (no framework-specific wrapper needed — use the service directly in components)Auth only works when served from Power Pages (not during local npm run dev). Add a development mock pattern in the auth service:
// In development (localhost), return mock user data for testing
const isDevelopment = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1';The mock should return a fake user with configurable roles so developers can test role-based UI locally.
src/types/powerPages.d.ts created with Power Pages type definitionssrc/services/authService.ts created with login/logout functionsGoal: Create role-checking utilities and framework-specific authorization components (guards, directives, wrapper components).
Reference: ${CLAUDE_PLUGIN_ROOT}/skills/setup-auth/references/authorization-reference.md
Create src/utils/authorization.ts with:
getUserRoles() — returns array of role names from current userhasRole(roleName) — case-insensitive single role checkhasAnyRole(roleNames) — OR check across multiple roleshasAllRoles(roleNames) — AND check across multiple rolesisAuthenticated() — re-exports from auth serviceisAdmin() — checks for "Administrators" rolehasElevatedAccess(additionalRoles) — checks admin or specified rolesBased on the detected framework:
React:
src/components/RequireAuth.tsx — renders children only for authenticated users, optional login prompt fallbacksrc/components/RequireRole.tsx — renders children only for users with specified roles, supports requireAll modesrc/hooks/useAuthorization.ts — hook returning { roles, hasRole, hasAnyRole, hasAllRoles, isAuthenticated, isAdmin }Vue:
src/composables/useAuthorization.ts — composable with computed roles and role-checking functionssrc/directives/vRole.ts — v-role directive for declarative role-based visibilityAngular:
src/app/guards/auth.guard.ts — CanActivateFn with route data for required rolessrc/app/directives/has-role.directive.ts — structural directive *appHasRole="'RoleName'"Astro:
src/utils/authorization.ts only (use directly in component scripts)Add a comment at the top of the authorization utilities:
// IMPORTANT: Client-side authorization is for UX only, not security.
// Server-side table permissions enforce actual access control.
// Always configure table permissions via /power-pages:integrate-webapi.src/utils/authorization.ts created with role-checking functionsGoal: Create the login/logout button component and integrate it into the site's navigation.
Based on the detected framework, create a login/logout button component:
src/components/AuthButton.tsx + src/components/AuthButton.csssrc/components/AuthButton.vuesrc/app/components/auth-button/auth-button.component.ts + template + stylessrc/components/AuthButton.astroThe component should:
Find the site's navigation component and integrate the auth button:
Do NOT replace the existing navigation — add the auth button alongside existing nav items.
Stage and commit the auth files:
git add -A
git commit -m "Add authentication service and auth UI component"Goal: Identify protected content areas and apply role-based authorization patterns to the site's components.
Analyze the site's components to find content that should be role-gated:
Present findings to the user and confirm which areas to protect.
Based on the user's choices, wrap the appropriate components:
React example:
<RequireAuth fallback={<p>Please sign in to view this content.</p>}>
<Dashboard />
</RequireAuth>
<RequireRole roles={['Administrators']} fallback={<p>Access denied.</p>}>
<AdminPanel />
</RequireRole>Vue example:
<div v-role="'Administrators'">
<AdminPanel />
</div>Angular example:
{ path: 'admin', component: AdminComponent, canActivate: [authGuard, roleGuard], data: { roles: ['Administrators'] } }Stage and commit:
git add -A
git commit -m "Add role-based access control to site components"Goal: Validate that all auth files exist, the project builds, and the auth UI renders correctly.
Confirm the following files were created:
src/types/powerPages.d.ts — Power Pages type declarationssrc/services/authService.ts — Auth service with login/logout functionssrc/hooks/useAuth.ts for React)src/utils/authorization.ts — Role-checking utilitiesRequireAuth.tsx, RequireRole.tsx for React)src/components/AuthButton.tsx for React)Read each file and verify it contains the expected exports and functions:
login, logout, getCurrentUser, isAuthenticated, fetchAntiForgeryTokenhasRole, hasAnyRole, hasAllRoles, getUserRolesRun the project build to catch any import errors, type errors, or missing dependencies:
npm run buildIf the build fails, fix the issues before proceeding.
Start the dev server and verify the auth button appears in the navigation:
npm run devUse Playwright to navigate to the site and take a snapshot to confirm the auth button is visible:
http://localhost:<port>If the auth button is not visible or the page has rendering errors, fix the issues.
Goal: Create required site settings, present a summary of all work, and prompt for deployment.
The site needs the Authentication/Registration/ProfileRedirectEnabled setting set to false to prevent Power Pages from redirecting users to a profile page after login (which doesn't exist in code sites).
Check if .powerpages-site/site-settings/ exists. If it does, create the site setting file:
node "${CLAUDE_PLUGIN_ROOT}/scripts/generate-uuid.js"Create .powerpages-site/site-settings/authentication-registration-profileredirectenabled.yml:
id: <UUID from generate-uuid.js>
name: Authentication/Registration/ProfileRedirectEnabled
value: falseReference:
${CLAUDE_PLUGIN_ROOT}/references/skill-tracking-reference.md
Follow the skill tracking instructions in the reference to record this skill's usage. Use --skillName "SetupAuth".
Present a summary of everything created:
| Component | File(s) | Status |
|---|---|---|
| Type Declarations | src/types/powerPages.d.ts | Created |
| Auth Service | src/services/authService.ts | Created |
| Auth Hook/Composable | src/hooks/useAuth.ts (or framework equivalent) | Created |
| Authorization Utils | src/utils/authorization.ts | Created |
| Auth Components | RequireAuth, RequireRole (or framework equivalent) | Created |
| Auth Button | src/components/AuthButton.tsx (or framework equivalent) | Created |
| Site Setting | ProfileRedirectEnabled = false | Created |
Use AskUserQuestion:
| Question | Options |
|---|---|
| Authentication and authorization are configured. To make login work, the site needs to be deployed. Would you like to deploy now? | Yes, deploy now (Recommended), No, I'll deploy later |
If "Yes, deploy now": Invoke /power-pages:deploy-site.
If "No": Remind the user:
"Remember to deploy your site using
/power-pages:deploy-sitewhen you're ready. Authentication will not work until the site is deployed with the new site settings."
After deployment (or if skipped), remind the user:
localhost/power-pages:integrate-webapi for actual data securityProfileRedirectEnabled site setting createdUse TaskCreate at the start to track each phase:
| Task | Description |
|---|---|
| Phase 1 | Check Prerequisites — verify site, framework, deployment, web roles |
| Phase 2 | Plan — gather requirements and get user approval |
| Phase 3 | Create Auth Service — auth service, types, framework hook/composable |
| Phase 4 | Create Authorization Utils — role-checking functions and components |
| Phase 5 | Create Auth UI — AuthButton component and navigation integration |
| Phase 6 | Implement Role-Based UI — apply authorization patterns to components |
| Phase 7 | Verify Auth Setup — validate files exist, build succeeds, auth UI renders |
| Phase 8 | Review & Deploy — site setting, summary, deployment prompt |
Update each task with TaskUpdate as phases are completed.
Begin with Phase 1: Check Prerequisites
8ccaae8
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.