LoginSignup
1
1

ローカルでデバッグ実行したWebアプリをAzure ADでSAML認証してみた

Posted at

はじめに

ASP .net coreで開発したWebアプリをローカルで実行する。
実行したアプリにAzure ADによるSAML認証を実行する。

プログラム

下記のPGに書いてある通りのサンプルプログラムを作成します。

↓ASP .net core web app(MVC)ではなく、ASP .net core web appなので注意!

image.png

Nugetに関しても同じものを入れておく。
image.png

ソリューションの構成としては以下の通りになる。
image.png

ただし、appsettings.jsonIdPMetadataに関してはAzureAD構築後に設定するのでいじらなくてよい。

Azure AD設定

Azure PortalでAzure ADを作成して、Enterprise applications>App applicationsの画面でNew applicationを押下

image.png

Create your own applicationを押下してアプリケーションを作成する

image.png

Set up single sign onを選択

SAMLを選択
image.png

Basic SAML Configuration

  • Identifier (Entity ID)
    アプリを特定可能なIDを入力。
    プログラム側のappsetting.jsonのIssuerに対応する。

  • Reply URL (Assertion Consumer Service URL)
    ローカルでプログラムをデバッグしてみて、URLを確かめる。
    URLに/Auth/AssertionConsumerServiceを付与したURLを入力する。

image.png

image.png

  • SAML Certificates

App Federation Metadata UrlのURL(metadata URL)をコピーしてプログラムのappsettings.jsonIdPMetadataに貼り付ける。
また、appsettings.jsonIssuerをBasic SAML Configuration>Identifier (Entity ID)と同じにする。

ここまで作成できたら、Azure ADにユーザを追加する。
一旦AzureADのトップ画面に戻って、Usersを選択。
image.png

New Userを選択。

↓こんな感じでユーザを登録する。
image.png

AzureAD>Enterprise applications>App applicationsの画面で作成したIdentifier(Entity ID)を選択。
Manage>Users and groups>Add user/group

↓こんな感じで、作成したユーザを選択する。
image.png

プログラム動作確認

プログラムをデバッグする。
↓Loginを押下
image.png

Azure ADにリダイレクトされる。

↓作成したユーザのメールアドレスを入力。
image.png

↓ここで、Identifier(Entity ID)へのユーザの割当をしていないと、以下のようなエラーがでてくる。

AADSTS50105: Your administrator has configured the application saml_sample_2
('6XXXXXXXXXXXXXXXXXXXXX') to block users unless they are specifically granted ('assigned') 
access to the application. The signed in user 'testuser1@XXXXXXXXXXXXXXXXXXXXXXXXXXXX.onmicrosoft.com' is blocked
 because they are not a direct member of a group with access,
 nor had access directly assigned by an administrator. Please contact your
 administrator to assign access to this application.

↓の質問を聞かれたらAsk Laterを選択。

Action Required Your organization requires additional security information. 
Follow the prompts to download and set up the Microsoft Authenticator app.

Stay sign inはNoを選択。

結果

↓SAML認証した属性情報をプログラムに読み込みできている。
image.png

参考

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