1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

WindowsアプリでのOAuth連携 メモ

Posted at
  • ネイティブアプリのOAuth連携 メモ の続き。

  • ネイティブアプリをOAuth連携する際には、OAuth PKCE連携が推奨されている。

  • アプリは認可サーバーに対して認可リクエストを行い、認可レスポンスを受けとる必要がある。

  • その際のWindowsアプリでの認可レスポンスの受信方法についてメモする。

Windowsアプリでの認可レスポンスの受信方法

以下の2手法がある模様。

WebAuthenticationBroker(Web認証ブローカー)の利用

  • UWPアプリ向け。
  • OpenID Connectや OAuth などのインターネット経由の認証プロトコルを使う認可サーバーに接続してユーザー認証する (あるいは認可を得る) 際に利用できる機能。
    • 外部ユーザーエージェントを利用する。
// 認可要求エンドポイント
string startURL = "https://<providerendpoint>?client_id=<clientid>&scope=<scopes>&response_type=token";
// 認可サーバーに登録したリダイレクトURI
string endURL = "http://<appendpoint>";

System.Uri startURI = new System.Uri(startURL);
System.Uri endURI = new System.Uri(endURL);

var webAuthenticationResult = 
        await Windows.Security.Authentication.Web.WebAuthenticationBroker.AuthenticateAsync( 
        Windows.Security.Authentication.Web.WebAuthenticationOptions.None, 
        startURI, 
        endURI);

Loopback Interface Redirection の利用

  • 従来のアプリ向け。
  • "http://127.0.0.1:{port}/{path} "などのようにローカル・ループバックでHTTPレスポンスを受け取る方式。
    • 例:Windowsではhostsファイルを編集される可能性があるので、localhostより、127.0.0.1を使用することが推奨される。
  • 認可サーバー対応:リダイレクトURIのうちポート番号を可変に扱えるようにする必要がある。
  • アプリ対応:「SO_EXCLUSIVEADDRUSE」ソケットオプションを設定して、他のアプリが同じソケットにバインドしないようにする必要がある。

参考情報

1
2
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
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?