Support per-entry AuthSessionType in SessionMap with flexible syntax#172
Support per-entry AuthSessionType in SessionMap with flexible syntax#172
Conversation
- Add Assert-IdleAuthSessionMatchesType validation function
- Make -AuthSessionType optional, acts as default
- Support typed SessionMap values: @{ AuthSessionType = 'X'; Session = Y }
- Normalize SessionMap internally with Session + Type
- Validate session types before returning from AcquireAuthSession
- Update wrapper New-IdleAuthSession to pass through optional parameter
- Add comprehensive tests for typed sessions, mixed types, validation
- Maintain backward compatibility with untyped values + required type
Co-authored-by: blindzero <13959569+blindzero@users.noreply.github.com>
- Update docs/use/providers.md with per-entry AuthSessionType info - Add comprehensive example for AD + EXO mixed auth scenario - Document typed session value format - Add backward compatibility note - Note: cmdlet reference will be regenerated by CI Co-authored-by: blindzero <13959569+blindzero@users.noreply.github.com>
blindzero
left a comment
There was a problem hiding this comment.
@copilot: make sure we do not keep any backward compatibility / legacy stuff in the code or Tests. Only the new way to be supported.
- Remove -AuthSessionType parameter entirely
- All SessionMap values must be typed: @{ AuthSessionType = 'X'; Session = Y }
- DefaultAuthSession must be typed
- Simplify normalization logic (no untyped support)
- Update all examples to use typed format
- Remove all backward compatibility tests
- All 40 tests pass
Co-authored-by: blindzero <13959569+blindzero@users.noreply.github.com>
- Re-add -AuthSessionType parameter (optional)
- When provided, allows simple untyped values: $credential instead of @{ AuthSessionType = 'X'; Credential = Y }
- When not provided, typed descriptors required for mixed types
- Renamed Session property to Credential for clarity
- Removed PSCustomObject support (only hashtable)
- Re-added provider setup and -Providers in documentation examples
- Updated all examples to show simple syntax with -AuthSessionType
- Mixed-type example uses typed syntax with Credential property
- Updated tests: 21 tests covering simple and typed syntax
- All tests pass
Co-authored-by: blindzero <13959569+blindzero@users.noreply.github.com>
blindzero
left a comment
There was a problem hiding this comment.
@copilot please review existing examples and Additional docs like providers, quickstart anf so on
- Remove deprecated empty @{} pattern
- Use simple -DefaultAuthSession syntax for single token
- Keep -AuthSessionType for all examples (simple syntax)
- Consistent with main provider usage documentation
Co-authored-by: blindzero <13959569+blindzero@users.noreply.github.com>
Reviewed all documentation and examples. Updated EntraID provider reference to remove deprecated empty @{} patterns and use consistent simple syntax. Changes in commit e59269b. Review Summary: All documentation now consistently shows:
|
blindzero
left a comment
There was a problem hiding this comment.
@copilot please also review examples for new authsession behavior and check other provider docu as well (EXO, AD)
- Add complete Device Code Flow example with MSAL.PS - Document prerequisites (MSAL.PS module, app registration) - Show how to configure app for public client flows - Include full example with broker setup - Addresses MFA-enabled environments use case Co-authored-by: blindzero <13959569+blindzero@users.noreply.github.com>
Reviewed all provider documentation and examples. Changes in commit a1b4560. Review Summary: All provider documentation now consistent with simple syntax for single-auth scenarios and typed syntax for mixed-type scenarios. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a1b45600db
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Pull request overview
Adds support for per-entry AuthSessionType in SessionMap for IdLE’s AuthSessionBroker, enabling mixed authentication types (e.g., AD credentials + OAuth tokens) within a single broker instance.
Changes:
- Made
-AuthSessionTypeoptional and introduced typed session descriptors (@{ AuthSessionType = ...; Credential = ... }) with normalization inNew-IdleAuthSessionBroker. - Added
Assert-IdleAuthSessionMatchesTypeand integrated runtime type validation before returning sessions. - Updated Pester tests and provider/auth documentation to reflect the new flexible syntax.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Core/New-IdleAuthSession.Tests.ps1 | Updates tests for simple vs typed syntax and adds basic type-validation assertions. |
| src/IdLE/Public/New-IdleAuthSession.ps1 | Public wrapper: makes -AuthSessionType optional and updates help/examples. |
| src/IdLE.Core/Public/New-IdleAuthSessionBroker.ps1 | Core implementation: normalizes SessionMap/default sessions into typed entries and validates on acquisition. |
| src/IdLE.Core/Private/Assert-IdleAuthSessionMatchesType.ps1 | New validation helper for Credential/OAuth/PSRemoting session shapes. |
| docs/use/providers.md | Updates usage docs for simple + mixed-type broker patterns; adds examples. |
| docs/reference/providers/provider-entraID.md | Updates EntraID provider examples, including a device-code flow example. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
- Fix PSRemoting validation to accept InvokeCommand method pattern (DirectorySync provider) - Re-add missing routing behavior tests (fallback, ambiguity, precedence) - Optimize validation function lookup (cache scriptblock on broker, avoid repeated Get-Command) - Fix OAuth validation to safely check for AccessToken property/method - Update test to use invalid type for OAuth validation All 24 tests pass. Cmdlet reference will be regenerated by CI. Co-authored-by: blindzero <13959569+blindzero@users.noreply.github.com>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (1)
docs/use/providers.md:160
- This sentence is now inaccurate given the new behavior: when
-AuthSessionTypeis provided, SessionMap/DefaultAuthSession values can be untyped (the broker supplies the default type). Consider rewording to clarify that either the broker has a defaultAuthSessionTypeor each entry is a typed descriptor with its ownAuthSessionType.
AuthSessionBroker session values must specify an `AuthSessionType` that determines validation rules, lifecycle management, and telemetry behavior:
- **`OAuth`** - Token-based authentication (e.g., Microsoft Graph, Exchange Online)
- **`PSRemoting`** - PowerShell remoting execution context (e.g., Entra Connect)
- **`Credential`** - Credential-based authentication (e.g., Active Directory, mock providers)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Implementation Complete: Per-Entry AuthSessionType with Flexible Syntax
✅ Simple syntax for single auth type + typed syntax for mixed types
Summary
Implemented per-entry AuthSessionType in SessionMap with both simple and typed syntax options.
Changes
1. Flexible Syntax
-AuthSessionTypeparameter (optional)-AuthSessionType):@{ Role = 'Admin' } = $credential@{ Role = 'Admin' } = @{ AuthSessionType = 'Credential'; Credential = $credential }SessiontoCredentialfor better clarity2. Testing
3. Validation
4. Documentation
docs/use/providers.md) - Complete ✅Usage Patterns
Simple (single auth type):
Simple with routing:
Mixed types (typed descriptors):
Device Code Flow (MFA-enabled environments):
Quality Assurance
Original prompt
This section details on the original issue you should resolve
<issue_title>AuthSessionBroker: Support per-entry AuthSessionType in SessionMap</issue_title>
<issue_description>## Problem Statement
New-IdleAuthSessionBrokercurrently requires a single-AuthSessionTypevalue which applies to all sessions returned by the broker.This is a limitation for realistic workflows where one
Providers.AuthSessionBrokermust serve multiple providers/systems in a single run.Example scenarios where a single broker must handle mixed session types:
PSCredential(Credential)Today, a
SessionMapcan technically contain different session value shapes (credential, token, etc.), butAuthSessionTypeis global and therefore cannot be correct for all entries.Additionally, the broker has a TODO comment explicitly stating that the current implementation “allows all options for all session types”, so the intended type-specific validation/lifecycle cannot be implemented correctly as long as the type is global.
Goal: enable one AuthSessionBroker instance to route different session types based on
AuthSessionName/AuthSessionOptions.Proposed Solution
1) Extend
New-IdleAuthSessionBrokerto support per-entry session typeIntroduce a typed session descriptor that can be used as the
SessionMapvalue.New supported value shapes:
@{ ...pattern... } = <any session object>@{ ...pattern... } = @{ AuthSessionType = 'Credential' | 'OAuth' | 'PSRemoting'; Session = <any> }@{ ...pattern... } = [pscustomobject]@{ AuthSessionType = 'Credential' | 'OAuth' | 'PSRemoting'; Session = <any> }The broker MUST normalize values internally into a consistent shape like:
Session(the object that will be returned to the provider)AuthSessionType(for validation / telemetry / lifecycle management)AcquireAuthSession(Name, Options)continues to return only the session object (backward compatible with provider method signatures).The type is used internally for validation and can optionally be surfaced via events/telemetry if needed.
2) Make
-AuthSessionTypeoptional and treat it as defaultChange parameter behavior:
-AuthSessionTypebecomes optional (but still validated if provided).-AuthSessionTypeis provided, it acts as DefaultAuthSessionType for:DefaultAuthSession(if set)SessionMapentries that are legacy (untyped) values-AuthSessionTypeis not provided:SessionMapentry MUST be typed (new shape), andDefaultAuthSessionMUST be typed if present (or explicitly forbidden without a type)This keeps backward compatibility while enabling mixed-type brokers.
3) Add type-specific validation hooks (minimal now, extensible later)
Implement a small internal validation function:
Assert-IdleAuthSessionMatchesType -AuthSessionType <type> -Session <object>Minimal validation (safe defaults, deterministic):
Credential: allow[pscredential](and optionally allowSecureStringonly if explicitly supported elsewhere — default: no)OAuth: allowstringtokens and/or a known token/container shape (keep minimal and well-defined)PSRemoting: allowPSSession,WSManConnectionInfo, or the existing session credential pattern used by the DirectorySync providerThe validation MUST fail fast with an actionable error message, including:
AuthSessionType4) Documentation & Examples
Update docs to reflect:
Suggested docs to update:
New-IdleAuthSessionBroker/New-IdleAuthSessionwrapper5) Tests
Add/extend Pester tests (unit tests, no live calls):
SessionMapvalues +-AuthSessionTyperequired behavior should still workAuthSessionType='Credential'but session is token string) fails with clear error💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.