![](/sites/default/files/inline/images/images/image(3117).png) この記事では、以下のオンラインデモを通じ、GitHub アカウントを使用した OAuth2 認証の基本を説明します。 https://dappsecurity.demo.community.intersystems.com/csp/user/index.csp(SuperUser | SYS) ## 推奨事項: * OAuth2 の概要: https://learning.intersystems.com/course/view.php?id=252 * ドキュメント: [OAuth2 クライアントとして InterSystems IRIS Web アプリケーションを使用する](https://docs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cls?KEY=GOAUTH_client) * 記事: https://community.intersystems.com/post/intersystems-iris-open-authorization-framework-oauth-20-implementation-part-1

目的を達成するために必要な 3 つのステップ:

* ステップ 1: GitHub 認証サーバーにアプリケーションを登録する * ステップ 2: InterSystems 管理ポータルから OAuth 2.0 クライアントを構成する * ステップ 3: GitHub アカウントでログインするための API を呼び出す それでは始めましょう。  ## ステップ 1: GitHub 認証サーバーにアプリケーションを登録する GitHub 認証サーバーにアプリケーションを登録するには、GitHub アカウントが必要です。  GitHub アカウントにログインして https://github.com/settings/developers に移動し、[OAuth Apps(OAuth アプリ)]タブで[New OAuth App(新しい OAuth アプリ)]ボタンをクリックします。 ![](/sites/default/files/inline/images/images/image(3134).png)   アプリケーション名、ホームページ URL、説明、および認証コールバック URL を入力します。 認証コールバック URL は **OAuth2.Response.cls** クラス({domain}/csp/sys/oauth2/OAuth2.Response.cls)を参照する必要があることに注意してください。 [Register Application(アプリケーションを登録)]をクリックします。 ![](/sites/default/files/inline/images/images/image(3135).png) すると、詳細ページが開きます。 [Generate a new client secret(新しいクライアントシークレットを生成)]をクリックし、IRIS OAuth2 クライアントを構成する際に使用するクライアント ID と秘密鍵を保存します。 ![](/sites/default/files/inline/images/images/image(3136).png) アプリケーションが登録されました。 ![](/sites/default/files/inline/images/images/image(3137).png) ## ステップ 2: InterSystems 管理ポータルから OAuth 2.0 クライアントを構成する [[システム](https://dappsecurity.demo.community.intersystems.com/csp/sys/%25CSP.Portal.Home.zen)]>[[セキュリティ管理](https://dappsecurity.demo.community.intersystems.com/csp/sys/%25CSP.Portal.Home.zen)]>[[OAuth 2.0 クライアント](https://dappsecurity.demo.community.intersystems.com/csp/sys/sec/%25CSP.UI.Portal.OAuth2.Client.ServerList.zen)]に移動し、[サーバーの説明を作成]ボタンをクリックします。 ![](/sites/default/files/inline/images/images/image(3138).png) 上部にある[手動]ボタンをクリックし、以下の詳細を入力してサーバーの説明を保存します。 ![](/sites/default/files/inline/images/images/image(3139).png) [[システム](https://dappsecurity.demo.community.intersystems.com/csp/sys/%25CSP.Portal.Home.zen)]>[[セキュリティ管理](https://dappsecurity.demo.community.intersystems.com/csp/sys/%25CSP.Portal.Home.zen)]>[[OAuth 2.0 クライアント](https://dappsecurity.demo.community.intersystems.com/csp/sys/sec/%25CSP.UI.Portal.OAuth2.Client.ServerList.zen)]に戻り、[クライアント構成]をクリックします。 ![](/sites/default/files/inline/images/images/image(3140).png) [一般]タブに詳細を入力します。 クライアントリダイレクト URL は、アプリケーションを GitHub に登録した際に入力した認証コールバック URLと同じであることに注意してください。 ![](/sites/default/files/inline/images/images/image(3141).png) [クライアント資格情報]に、アプリケーションを GitHub に登録した際に生成したクライアント ID とクライアントシークレットを入力し、クライアント構成を保存します。 ![](/sites/default/files/inline/images/images/image(3142).png) ## ステップ 3: GitHub アカウントでログインするための API を呼び出す オンラインデモ(https://dappsecurity.demo.community.intersystems.com/csp/user/index.csp)に移動し、 SuperUser | SYS でログインします。 トップメニューから[Login with GitHub(GitHub でログイン)]をクリックします。 ![](/sites/default/files/inline/images/images/image(3143).png) これで、Oauth.cls ページが開きます。 サインインを試す前に、必ず GitHub からログアウトしてください。 [GitHub Sign In(GitHub サインイン)]をクリックします。 ![](/sites/default/files/inline/images/images/image(3144).png) システムは **%SYS.OAuth2.Authorization** クラス(https://docs.intersystems.com/latest/csp/documatic/%25CSP.Documatic.cls?&LIBRARY=%25SYS&PRIVATE=1&CLASSNAME=%25SYS.OAuth2.Authorization)の **GetAuthorizationCodeEndpoint** メソッドを使用して、GitHub 認証サーバーに移動します。 ![](/sites/default/files/inline/images/images/image(3145).png) ログインに成功すると、システムは OauthRe.cls ページにリダイレクトします。 ![](/sites/default/files/inline/images/images/image(3147).png) コードは https://github.com/mwaseem75/Data\_APP\_Security のリポジトリから入手できます。   以上です!