1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

現時点でのMicrosoft アカウントの認証方法まとめ

Posted at

自分のアプリを Microsoft アカウントで認証させる際に、これまで様々な方法がありましたが、現時点での状況についてまとめておきます。備忘録を兼ねて。

接続方法

方法 状況 備考
MSAL (Microsoft.Identity.Client) ✅ 推奨・サポート中 個人アカウントも対応
Azure.Identity (InteractiveBrowserCredential) ◯ 条件付き対応 Azure SDK 寄り
Live.com OAuth2 (旧API) ❌廃止方向 Graph API を使うべき
ADAL ❌ 廃止済み MSAL に移行必須
OpenID Connect 汎用ライブラリ ◯ 利用可能 標準 OIDC ライブラリでも可

MSAL (Microsoft.Identity.Client)

  • 現在の標準。個人用 Microsoft アカウント(MSA)も Azure AD も対応している。
  • Microsoft Graph API、OneDrive、Outlook などと連携できる。
  • PKCE や Device Code Flow など各種フローに対応している。
c# での使用例
var app = PublicClientApplicationBuilder.Create("your-client-id")
    .WithTenantId("your-tenant-id")
    .WithRedirectUri("http://localhost")
    .Build();

var result = await app.AcquireTokenInteractive(new[] { "User.Read" }).ExecuteAsync();

Azure.Identity の認証クレデンシャル

  • API としては InteractiveBrowserCredential など。
  • 主に Azure SDK 向け。
  • ユーザー対話型ログインも可能。
  • Microsoft アカウントにも使えるが、Azure サービスへの接続が主目的。
c# での使用例
var credential = new InteractiveBrowserCredential();

var client = new SecretClient(new Uri("https://<your-keyvault-name>.vault.azure.net/"), credential);

Microsoft アカウントの OAuth2 を直接使用(非推奨)

  • 自前で Microsoft アカウントの OAuth2 エンドポイントを呼び出す。
  • https://login.live.com/oauth20_authorize.srf などを使用する。
  • client_id, response_type, redirect_uri, scope を指定して、ブラウザで認可する。

旧 ADAL (Azure Active Directory Authentication Library) (廃止)

  • MSAL の前身。Microsoft.IdentityModel.Clients.ActiveDirectory
  • 2022年6月に完全サポート終了
  • 現在は MSAL に移行必須

使い分け

用途に応じて向き不向きがあるので、こんな風に使い分けるといいかと。

目的 向いている API
Microsoft Graph を使いたい PublicClientApplicationBuilder(MSAL)
Azure SDK(Blob, KeyVault, etc)を使いたい InteractiveBrowserCredential
トークンキャッシュやアカウント制御が必要 PublicClientApplicationBuilder
認証処理をシンプルに済ませたい InteractiveBrowserCredential
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?