2016-11-11 7 views
0

私たちが達成しようとしているのは、フロントエンドのAngular-2とバックエンドASP.NET Web APIアプリケーションの役割ベースのセキュリティです。 ADAL.jsの助けを借りて認証プロセスを行い、トークンをローカルストレージに保存しています。また、hereというアプローチを実装しました。つまり、Graphi APIを呼び出して、ユーザーグループにクレームを埋め込むようにしました。ADAL.jsとASP.NET Web APIを使用するロール/グループベースの承認

私の質問は:とにかく、ローカルストレージにあるbearerTokenにサーバーからの役割要求を追加できますか。あるいは、この問題に近づくための良い方法があります。

答えて

0

上記コードサンプルは、グループに基づいてロールを割り当てます。 Azure ADベーシックバージョンをお持ちの場合は、ユーザー/グループに直接ロールを割り当てることができます。

私の質問は:とにかく、サーバーからローカル記憶域にあるbearerTokenに役割要求を追加できますか。あるいは、この問題に近づくための良い方法があります。

はい、可能です。ロールクレームを発行するには、ユーザまたはグループにロールを割り当てるためにユーザを割り当てる必要があります。その後、ユーザーがトークンを取得すると、Azure ADはトークン内の相対ロールクレームを発行します。

ロールクレームを使用するコードサンプルは、hereから参照できます。

また、groups claim developingに興味があるかもしれません。

+0

は、ロールに私たちのグループをマッピングし、AzureのActive Directoryのプレミアムのために行くことなく、役割ベースの認証を行うことです。 とにかく、ADAL.jsを使用してトークンを取得してから、サーバー側でMicrosoft Graph APIを呼び出してグループをトークンに挿入できますか? – Pickle

+1

いいえ、不可能です。トークンはAzure ADから発行/署名されているためです。セキュリティの考慮事項のためにトークンを変更することはできません。 –

0

私はしばらくこのことに苦労していました。私はそれを考え出しました。

最初に、 Azure ADでは、WebApiアプリをアプリケーションタイプとしてWeb App/APIに設定します。 は、ネイティブアプリになると、あなたは上記の追加サービスに必要なアクセス許可を追加するファイルをマニフェストし、次にアプリケーションの種類などのクライアントアプリケーションを作成

[ 
    { 
     "allowedMemberTypes": [ 
     "User" 
     ], 
     "displayName": "Reviewer", 
     "id": "0238c2bb-9857-4d07-b760-a47ec621d57a", 
     "isEnabled": true, 
     "description": "Reviewer only have the ability to view tasks and their statuses.", 
     "value": "reviewer" 
    }, 
    { 
     "allowedMemberTypes": [ 
     "User" 
     ], 
     "displayName": "Approver", 
     "id": "000018cb-19e3-4f89-bf99-5d7acf30773b", 
     "isEnabled": true, 
     "description": "Approvers have the ability to change the status of tasks.", 
     "value": "approver" 
    } 
    ] 

のようなあなたの役割を追加するために行きます。 SPA角度アプリで

この

var endPoints = { 
     // "https://localhost:44386/" is the API URL 
     // "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx" is the Service Application ID 
     "https://localhost:44386/": "xxxxxxxxxxxxxxxxxxxxxxxxxx" 
    }; 
    adalAuthenticationServiceProvider.init({ 
     instance: "https://login.microsoftonline.com/", 
     // tenant is your tenant name (something like below) 
     tenant: "{NAME}.onmicrosoft.com", 
     // this is the Native app application ID (ClientID) you registered 
     clientId: "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyy", 
     extraQueryParameter: "nux=1", 
     endpoints: endPoints 
    }, $httpProvider); 
} 

])のようなものを追加します。その後

、ごstartup.csに次のようなサービスアプリケーションを設定する必要があります。

 app.UseWindowsAzureActiveDirectoryBearerAuthentication(
      new WindowsAzureActiveDirectoryBearerAuthenticationOptions 
      { 
       TokenValidationParameters = new TokenValidationParameters 
       { 
       /* "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx" is the Service Application ID. (Same as you registered in the client app above)*/ 
        ValidAudience = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx", 
        RoleClaimType = "roles" 
       }, 
       /*enant is your tenant name (same as you registered in client app above)*/ 
       Tenant = "{NAME}.onmicrosoft.com" 
      }); 

最後に、あなたは= Azureのアクティブディレクトリ=>エンタープライズアプリケーション=>すべてのアプリケーションに移動する必要があります>を選択あなたのwebAPIサービス=>ユーザーとグループ=>ユーザーをロールに割り当てます。あなたが役割

このアプローチを学ぶことが
0

良いが含まれている適切なベアラ・トークンを置く認証しWEBAPI、adal.jsとADA-angular.jsを呼び出すために、クライアントアプリケーションを通じてログインしたときにこれが全て行われ

あなたのソリューションを共有してくれてありがとう!

Azure ADマニフェストファイルの操作に精通していないユーザー向けです。以下は良いリソースです。私たちは基本的に達成したい何 https://thinkthencode.wordpress.com/2016/04/24/azure-ad-using-app-roles-for-authorization/

"appRoles": [ 
     { 
    "allowedMemberTypes": [ 
    "User" 
    ], 
    "displayName": "Reviewer", 
    "id": "0238c2bb-9857-4d07-b760-a47ec621d57a", 
    "isEnabled": true, 
    "description": "Reviewer only have the ability to view tasks and their statuses.", 
    "value": "reviewer" 
}, 
{ 
    "allowedMemberTypes": [ 
    "User" 
    ], 
    "displayName": "Approver", 
    "id": "000018cb-19e3-4f89-bf99-5d7acf30773b", 
    "isEnabled": true, 
    "description": "Approvers have the ability to change the status of tasks.", 
    "value": "approver" 
} 
    ] 
関連する問題