claude-skills/

Anthropic公式スキル・プラグインの日本語ディレクトリ

last sync 22h ago
スキルOfficialsecurity

🔐auth0-wpf

プラグイン
auth0
ライセンス
Apache-2.0

説明

次のような場合に使用: WPF デスクトップアプリケーションに Auth0 のログイン・ログアウト機能やトークン管理を追加する場合。 Auth0.OidcClient.WPF を統合します。 ユーザーが「WPF アプリにログインを追加したい」または「Windows デスクトップアプリに Auth0 を導入したい」と言った場合にも使用してください。

原文を表示

Use when adding Auth0 login, logout, or token management to a WPF desktop application. Integrates Auth0.OidcClient.WPF — use even if the user says "add login to my WPF app" or "add Auth0 to my Windows desktop app".

ユースケース

  • WPFデスクトップアプリにログイン機能を追加するとき
  • Auth0のトークン管理を実装するとき
  • Windowsデスクトップアプリに認証を導入するとき
  • WPFアプリにログアウト機能を追加するとき

本文(日本語訳)

Auth0 WPF インテグレーション

WPF(Windows Presentation Foundation)デスクトップアプリケーションにAuth0認証を追加します。 このスキルは Auth0.OidcClient.WPF NuGetパッケージを統合します。 このパッケージはWebView2を使用して、ポップアップウィンドウ内にAuth0ログインページを表示し、PKCEを用いたOIDCベースのセキュアなログイン・ログアウトフローを実現します。

SDKはWebAuth(PKCEを使用したOIDC認可コードフロー)を実行する際、WPF Windowにホストされたコントロール内でAuth0 Universal Loginページを表示します。 Info.plistやAndroidManifest.xmlへのURLスキーム登録が必要なネイティブモバイルSDKとは異なり、WPF SDKはコールバックをWebView2のナビゲーションイベント内で完結させます。カスタムURL Typeやプロトコルハンドラーは不要です。

Agentへの指示: SDKセットアップ手順を提示する前に、以下のコマンドを実行して最新リリースバージョンを取得してください:

gh api repos/auth0/auth0-oidc-client-net/releases --jq '[.[] | select(.tag_name | startswith("wpf-")) | .tag_name | ltrimstr("wpf-")] | .[0]'

以下に記載されているハードコードされたバージョンの代わりに、取得したバージョンをすべての依存関係の記述に使用してください。

前提条件

  • .NET 6.0 SDK 以降(WPFはWindowsが必須)
  • Visual Studio 2022 または JetBrains Rider(.NETデスクトップ開発ワークロード含む)
  • Windows 10 以降
  • Microsoft Edge WebView2 Runtime(Windows 11に同梱、Windows 10では別途インストール可)
  • Nativeアプリケーションが設定済みのAuth0アカウント
  • Node.js 20以降(Auth0 CLI自動セットアップ用)

使用すべきでない場合

ユースケース 推奨スキル
.NET MAUIクロスプラットフォームアプリ auth0-maui
Windows Formsデスクトップアプリ auth0-winforms
ASP.NET Coreサーバーサイドウェブアプリ auth0-aspnetcore-authentication
ASP.NET Core Web API(JWT検証) auth0-aspnetcore-api
iOSのみのSwiftアプリ auth0-swift
Androidのみのkotlinアプリ auth0-android

クイックスタート手順

Agentへの指示: 開始前に、ユーザーのプロジェクトを以下の観点で確認してください:

  1. .csproj ファイルの TargetFramework から .NETバージョンを特定する
  2. コードベースに既存の認証プロバイダーが存在するか確認する — 既存の Auth0Client または WebViewBrowser の使用箇所を検索し、見つかった場合は再利用する
  3. プロジェクトの名前空間とディレクトリの規則を把握する
  1. SDKのインストール: dotnet add package Auth0.OidcClient.WPF
  2. Auth0の設定: 自動または手動での設定方法は セットアップガイド を参照してください。
  3. 認証の組み込み: Auth0Client の初期化を追加し、XAMLのボタンクリックハンドラーにログイン・ログアウトを紐付けます。
  4. ビルドと確認: dotnet build

Agentへの指示: Auth0Client の設定を記述する際は以下に注意してください:

  • このスキルのインテグレーションガイドに記載された正確なコードパターンを使用する。
  • SDKはWebView2を使用してログインページをポップアップウィンドウ内に表示します — カスタムブラウザのセットアップは不要です。
  • デフォルトのコールバックURLは https://{yourDomain}/mobile です — Auth0ダッシュボードの「Allowed Callback URLs」および「Allowed Logout URLs」にこのURLを追加する必要があります。
  • https://{domain}/ios/{bundleId}/callback のようなプラットフォーム固有のパターンを使用するネイティブモバイルSDKとは異なり、WPFではシンプルな https://{domain}/mobile コールバック形式を使用します。

設定とコードの記述後、ビルドが成功することを確認してください:

dotnet build

ビルドが失敗した場合は問題の修正を試みてください。5〜6回試みても失敗する場合は、ユーザーに助けを求めてください。

コールバックURLの設定

WPF SDKのデフォルトコールバックURLは https://{yourDomain}/mobile です。 これはモバイルネイティブSDKとは異なります:

  • モバイルSDKhttps://{domain}/ios/{bundleId}/callbackhttps://{domain}/android/{packageName}/callback のようなプラットフォーム固有のコールバックを使用します
  • WPF / WinForms は汎用的な https://{yourDomain}/mobile コールバックを使用します

コールバックはWebView2コントロールの NavigationStarting イベントによってインターセプトされるため、システムレベルのURLスキーム登録は不要です。 Info.plist、AndroidManifest.xml、またはWindowsプロトコルハンドラーの設定は一切必要ありません。

Auth0ダッシュボードで以下を設定してください:

  • Allowed Callback URLs: https://{yourDomain}/mobile
  • Allowed Logout URLs: https://{yourDomain}/mobile

完了の条件

  • [ ] Auth0.OidcClient.WPF パッケージがインストールされている
  • [ ] Auth0Client にDomainとClientIdが設定されている
  • [ ] ログイン・ログアウトフローが動作している(認証時にWebView2ポップアップが開く)
  • [ ] ログイン後にユーザープロファイルのクレームにアクセスできる
  • [ ] コールバックURL https://{yourDomain}/mobile がAuth0ダッシュボードに登録されている
  • [ ] エラーなくビルドが成功する
  • [ ] 実機(リモートデスクトップではなく物理的なWindowsマシン)でテスト済み

詳細ドキュメント

よくある間違い

間違い 修正方法
Auth0ダッシュボードでアプリタイプが Native に設定されていない ダッシュボードの設定でアプリケーションタイプを「Native」に変更する
Auth0ダッシュボードにコールバックURLが登録されていない 「Allowed Callback URLs」と「Allowed Logout URLs」の両方に https://{yourDomain}/mobile を追加する
Domainの設定に https:// プレフィックスを使用している Domainはホスト名のみを指定する(例: tenant.auth0.comhttps://tenant.auth0.com ではない)
WebView2 Runtimeがインストールされていない Windows 10にMicrosoft Edge WebView2 Runtimeをインストールする(Windows 11には同梱済み)
トークンリフレッシュ用の offline_access スコープを要求していない Auth0ClientOptionsScopeoffline_access を追加する
コード内にClientSecretを記述している ネイティブアプリはClient Secretを使用しない — 削除すること
レジストリ・マニフェストへのURLスキーム登録を試みている WPFはWebView2をプロセス内で使用するため、URLスキーム登録は不要(AppxManifestが必要なMAUIとは異なる)

テストに関する注意事項

Agentへの指示: 実機でテストするようユーザーに案内してください。WebView2の一部の動作(ポップアップウィンドウ、証明書の処理など)は、リモートデスクトップや仮想マシン環境と物理的なWindowsマシンとで異なる場合があります。リリース前に、実際のハードウェア上でログイン → WebView2 → コールバック → トークン取得のフロー全体をテストしてください。

テストチェックリスト:

  • ログインフロー: ログインボタンをクリック → WebView2ポップアップが開く → 認証 → ポップアップが閉じる → ユーザー情報が表示される
  • ログアウトフロー: ログアウトボタンをクリック → WebView2ポップアップが開く → セッションがクリアされる → ポップアップが閉じる
  • トークンリフレッシュ: 保存済みリフレッシュトークンを使った RefreshTokenAsync が動作する
  • キャンセル: ユーザーがWebView2ウィンドウを閉じた際に、アプリが UserCancel を適切に処理する
  • 実機テスト: 仮想環境だけでなく実際のWindowsマシンでテストする
  • 複数回ログイン: ログアウト後に再ログインが正常に動作することを確認する(古い状態が残らないこと)

関連スキル

  • auth0-winforms — Windows Formsデスクトップアプリ
  • auth0-maui — .NET MAUIクロスプラットフォームアプリ
  • auth0-aspnetcore-authenticationASP.NET Coreサーバーサイドウェブアプリ
  • auth0-aspnetcore-apiJWT検証を使用したASP.NET Core Web API

クイックリファレンス

using Auth0.OidcClient;
using System.Diagnostics;

// クライアントの初期化
var client = new Auth0Client(new Auth0ClientOptions
{
    Domain = "{yourDomain}",
    ClientId = "{yourClientId}",
    Scope = "openid profile email offline_access"
});

// ログイン — WebView2ポップアップウィンドウを開く(PKCEを使用したWebAuthフロー)
var loginResult = await client.LoginAsync();
if (!loginResult.IsError)
{
    var user = loginResult.User;
    var name = user.FindFirst(c => c.Type == "name")?.Value;
    var email = user.FindFirst(c => c.Type == "email")?.Value;
    var picture = user.FindFirst(c => c.Type == "picture")?.Value;

    Debug.WriteLine($"name: {name}");
    Debug.WriteLine($"email: {email}");

    foreach (var claim in loginResult.User.Claims)
    {
        Debug.WriteLine($"{claim.Type} = {claim.Value}");
    }
}

// 後で使用するためにログイン時のリフレッシュトークンを保存する
var refreshToken = loginResult.RefreshToken;

// ログアウト
await client.LogoutAsync();

// トークンリフレッシュ(offline_accessスコープが必要)
var refreshResult = await client.RefreshTokenAsync(refreshToken);
if (refreshResult.IsError == false)
{
    var newAccessToken = refreshResult.AccessToken;
}

MainWindow.xaml(WPF UI)

<Window x:Class="MyApp.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Auth0 WPF App" Height="450" Width="800">
    <Grid>
        <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
            <Button x:Name="LoginButton" Content="Login" Width="200" Height="40"
                    Margin="10" Click="LoginButton_Click" FontSize="16"/>
            <Button x:Name="LogoutButton" Content="Logout" Width="200" Height="40"
                    Margin="10" Click="LogoutButton_Click" FontSize="16"/>
        </StackPanel>
    </Grid>
</Window>

MainWindow.xaml.cs(WPFコードビハインド)

using Auth0.OidcClient;
using System.Diagnostics;

namespace MyApp;

public partial class MainWindow : Window
{
    private Auth0Client _client;

    public MainWindow()
    {
        InitializeComponent();

        _client = new Auth0Client(new Auth0ClientOptions
        {
            Domain = "{yourDomain}",
            ClientId = "{yourClientId}",
            Scope = "openid profile email offline_access"
        });
    }

    private async void LoginButton_Click(object sender, RoutedEventArgs e)
    {
        var loginResult = await _client.LoginAsync();

        if (loginResult.IsError)
        {
            Debug.WriteLine($"ログイン中にエラーが発生しました: {loginResult.Error}");
            return;
        }

        var user = loginResult.User;
        var name = user.FindFirst(c => c.Type == "name")?.
原文(English)を表示

Auth0 WPF Integration

Add Auth0 authentication to WPF (Windows Presentation Foundation) desktop applications. This skill integrates the Auth0.OidcClient.WPF NuGet package which uses WebView2 to display the Auth0 login page in a popup window for secure OIDC-based login and logout flows with PKCE.

The SDK performs WebAuth (OIDC authorization code flow with PKCE) by opening the Auth0 Universal Login page inside a WebView2 control hosted in a WPF Window. Unlike native mobile SDKs that require URL scheme registration in Info.plist or AndroidManifest.xml, the WPF SDK handles the callback entirely within the WebView2 navigation events — no custom URL Types or protocol handlers are needed.

Agent instruction: Before providing SDK setup instructions, fetch the latest release version by running:

gh api repos/auth0/auth0-oidc-client-net/releases --jq '[.[] | select(.tag_name | startswith("wpf-")) | .tag_name | ltrimstr("wpf-")] | .[0]'

Use the returned version in all dependency lines instead of any hardcoded version below.

Prerequisites

  • .NET 6.0 SDK or later (WPF requires Windows)
  • Visual Studio 2022 or JetBrains Rider with .NET desktop development workload
  • Windows 10 or later
  • Microsoft Edge WebView2 Runtime (included with Windows 11, installable on Windows 10)
  • Auth0 account with a Native application configured
  • Node.js 20+ (for Auth0 CLI automated setup)

When NOT to Use

Use Case Recommended Skill
.NET MAUI cross-platform app auth0-maui
Windows Forms desktop app auth0-winforms
ASP.NET Core server-side web app auth0-aspnetcore-authentication
ASP.NET Core Web API (JWT validation) auth0-aspnetcore-api
iOS-only Swift app auth0-swift
Android-only Kotlin app auth0-android

Quick Start Workflow

Agent instruction: Before starting, examine the user's project:

  1. Identify the .NET version from the .csproj file (TargetFramework)
  2. Check if there is already an existing authentication provider in the codebase — search for existing Auth0Client or WebViewBrowser usage and reuse if found
  3. Note the project's namespace and directory conventions
  1. Install SDK: dotnet add package Auth0.OidcClient.WPF
  2. Configure Auth0: See Setup Guide for automatic or manual configuration.
  3. Integrate authentication: Add Auth0Client initialization and wire login/logout to XAML button click handlers.
  4. Build and verify: dotnet build

Agent instruction: When writing the Auth0Client configuration:

  • Use the exact code patterns from this skill's integration guide.
  • The SDK uses WebView2 to show the login page in a popup window — no custom browser setup needed.
  • The default callback URL is https://{yourDomain}/mobile — this must be added to Auth0 Dashboard Allowed Callback URLs and Allowed Logout URLs.
  • Unlike native mobile SDKs that use https://{domain}/ios/{bundleId}/callback or similar platform-specific patterns, WPF uses the simpler https://{domain}/mobile callback format.

After writing configuration and code, verify the build succeeds:

dotnet build

If the build fails, attempt to fix the issue. After 5-6 failed attempts, ask the user for help.

Callback URL Configuration

The WPF SDK uses https://{yourDomain}/mobile as its default callback URL. This differs from mobile native SDKs:

  • Mobile SDKs use platform-specific callbacks like https://{domain}/ios/{bundleId}/callback or https://{domain}/android/{packageName}/callback
  • WPF/WinForms use the generic https://{yourDomain}/mobile callback

The callback is intercepted by the WebView2 control's NavigationStarting event — no system-level URL scheme registration is required. You do NOT need to configure Info.plist, AndroidManifest.xml, or Windows protocol handlers.

Configure in the Auth0 Dashboard:

  • Allowed Callback URLs: https://{yourDomain}/mobile
  • Allowed Logout URLs: https://{yourDomain}/mobile

Done When

  • [ ] Auth0.OidcClient.WPF package installed
  • [ ] Auth0Client configured with Domain and ClientId
  • [ ] Login/logout flow working (WebView2 popup opens for authentication)
  • [ ] User profile claims accessible after login
  • [ ] Callback URL https://{yourDomain}/mobile registered in Auth0 Dashboard
  • [ ] Build succeeds with no errors
  • [ ] Tested on real device (physical Windows machine, not just remote desktop)

Detailed Documentation

  • Setup Guide — Auth0 tenant configuration, SDK installation, callback URL setup
  • Integration Patterns — Login/logout flows, token refresh, user profile, error handling
  • API Reference & Testing — Full Auth0ClientOptions reference, claims, testing checklist, troubleshooting

Common Mistakes

Mistake Fix
App type not set to Native in Auth0 Dashboard Change application type to "Native" in Dashboard settings
Missing callback URL in Auth0 Dashboard Add https://{yourDomain}/mobile to both Allowed Callback URLs AND Allowed Logout URLs
Using https:// prefix in Domain config Domain should be hostname only (e.g., tenant.auth0.com, not https://tenant.auth0.com)
WebView2 Runtime not installed Install Microsoft Edge WebView2 Runtime on Windows 10 (included with Windows 11)
Not requesting offline_access scope for token refresh Add offline_access to Scope in Auth0ClientOptions
Storing ClientSecret in code Native apps do NOT use a Client Secret — remove it
Trying to register URL scheme in registry/manifest WPF uses WebView2 in-process — no URL scheme registration needed (unlike MAUI which needs AppxManifest)

Testing Notes

Agent instruction: Remind the user to test on a physical device. Some WebView2 behaviors (popup windows, certificate handling) may differ in remote desktop or virtual machine environments vs. physical Windows machines. Test the full login → WebView2 → callback → token flow on real hardware before shipping.

Testing Checklist:

  • Login flow: Click login → WebView2 popup opens → authenticate → popup closes → user info displayed
  • Logout flow: Click logout → WebView2 popup opens → session cleared → popup closes
  • Token refresh: RefreshTokenAsync with stored refresh token works
  • Cancel: User closes WebView2 window → app handles UserCancel gracefully
  • Physical device: Test on a real Windows machine (not just virtual environment)
  • Multiple logins: Verify login works after logout (no stale state)

Related Skills

  • auth0-winforms — Windows Forms desktop apps
  • auth0-maui — .NET MAUI cross-platform apps
  • auth0-aspnetcore-authenticationASP.NET Core server-side web apps
  • auth0-aspnetcore-apiASP.NET Core Web API with JWT validation

Quick Reference

using Auth0.OidcClient;
using System.Diagnostics;

// Initialize client
var client = new Auth0Client(new Auth0ClientOptions
{
    Domain = "{yourDomain}",
    ClientId = "{yourClientId}",
    Scope = "openid profile email offline_access"
});

// Login — opens WebView2 popup window (WebAuth flow with PKCE)
var loginResult = await client.LoginAsync();
if (!loginResult.IsError)
{
    var user = loginResult.User;
    var name = user.FindFirst(c => c.Type == "name")?.Value;
    var email = user.FindFirst(c => c.Type == "email")?.Value;
    var picture = user.FindFirst(c => c.Type == "picture")?.Value;

    Debug.WriteLine($"name: {name}");
    Debug.WriteLine($"email: {email}");

    foreach (var claim in loginResult.User.Claims)
    {
        Debug.WriteLine($"{claim.Type} = {claim.Value}");
    }
}

// Store the refresh token from login for later use
var refreshToken = loginResult.RefreshToken;

// Logout
await client.LogoutAsync();

// Refresh token (requires offline_access scope)
var refreshResult = await client.RefreshTokenAsync(refreshToken);
if (refreshResult.IsError == false)
{
    var newAccessToken = refreshResult.AccessToken;
}

MainWindow.xaml (WPF UI)

<Window x:Class="MyApp.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Auth0 WPF App" Height="450" Width="800">
    <Grid>
        <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
            <Button x:Name="LoginButton" Content="Login" Width="200" Height="40"
                    Margin="10" Click="LoginButton_Click" FontSize="16"/>
            <Button x:Name="LogoutButton" Content="Logout" Width="200" Height="40"
                    Margin="10" Click="LogoutButton_Click" FontSize="16"/>
        </StackPanel>
    </Grid>
</Window>

MainWindow.xaml.cs (WPF Code-Behind)

using Auth0.OidcClient;
using System.Diagnostics;

namespace MyApp;

public partial class MainWindow : Window
{
    private Auth0Client _client;

    public MainWindow()
    {
        InitializeComponent();

        _client = new Auth0Client(new Auth0ClientOptions
        {
            Domain = "{yourDomain}",
            ClientId = "{yourClientId}",
            Scope = "openid profile email offline_access"
        });
    }

    private async void LoginButton_Click(object sender, RoutedEventArgs e)
    {
        var loginResult = await _client.LoginAsync();

        if (loginResult.IsError)
        {
            Debug.WriteLine($"An error occurred during login: {loginResult.Error}");
            return;
        }

        var user = loginResult.User;
        var name = user.FindFirst(c => c.Type == "name")?.Value;
        var email = user.FindFirst(c => c.Type == "email")?.Value;
        var picture = user.FindFirst(c => c.Type == "picture")?.Value;

        Debug.WriteLine($"name: {name}");
        Debug.WriteLine($"email: {email}");

        foreach (var claim in loginResult.User.Claims)
        {
            Debug.WriteLine($"{claim.Type} = {claim.Value}");
        }
    }

    private async void LogoutButton_Click(object sender, RoutedEventArgs e)
    {
        await _client.LogoutAsync();
    }
}

References

原文・著作権は Anthropic および各プラグイン作者に帰属します。日本語訳は Claude API による自動翻訳です。