私はMicrosoft.Owin
ミドルウェアを使用して、自分のページにアクセスしたときにAzure ADに対するユーザーを認証します。Owinを使用してAzure ADに対してユーザーを認証したら、このユーザーとしてCRM Online Web APIにサイレントでアクセスできますか?
App_Start> Startup.cs
using Owin;
using System.Configuration;
using System.Globalization;
using Microsoft.Owin;
using Microsoft.Owin.Security;
using Microsoft.Owin.Security.Cookies;
using Microsoft.Owin.Security.OpenIdConnect;
using Microsoft.Owin.Extensions;
[assembly:OwinStartup(typeof(MyApp.App_Start.Startup))]
namespace MyApp.App_Start
{
public class Startup
{
private static string clientId = ConfigurationManager.AppSettings["ida:ClientId"];
private static string aadInstance = ConfigurationManager.AppSettings["ida:AADInstance"];
private static string tenant = ConfigurationManager.AppSettings["ida:Tenant"];
private static string postLogoutRedirectUri = ConfigurationManager.AppSettings["ida:PostLogoutRedirectUri"];
string authority = string.Format(CultureInfo.InvariantCulture, aadInstance, tenant);
public void Configuration(IAppBuilder app)
{
ConfigureAuth(app);
}
public void ConfigureAuth(IAppBuilder app)
{
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions() { });
app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions
{
ClientId = clientId,
Authority = authority,
PostLogoutRedirectUri = postLogoutRedirectUri,
Notifications = new OpenIdConnectAuthenticationNotifications
{
AuthenticationFailed = (context) =>
{
context.HandleResponse();
context.Response.Redirect("/Error/message=" + context.Exception.Message);
return System.Threading.Tasks.Task.FromResult(0);
}
}
});
app.UseStageMarker(PipelineStage.Authenticate);
}
}
}
この私が、このような自分のIDとしてこのユーザーに関する情報を取得するためにClaimsPrincipal
のようなものを使用することができ、それらが署名した後、正常に動作している:
string signedInUserID
= ClaimsPrincipal.Current.FindFirst(System.IdentityModel.Claims.ClaimTypes.NameIdentifier).Value;
string tenantID
= ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/tenantid").Value;
string userObjectID
= ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier").Value;
このユーザーとしてCRM Onlineに対してサイレント認証を行い、Web APIからデータを取得できるようになりました。これは可能ですか?あれば、どうですか?
私は私が正常に取得するように見えるAuthenticationContext
を経由してアクセストークンを取得する例を実行しようとしてきたが、その後、私はCRMオンラインを照会することができないよ、私は、セキュリティに関するさまざまなエラーが発生します。簡潔にするために、特に誰かがそれを見る必要がない限り、私はここにすべてのコードを記載しません。 Here's the MSDN article that gives the basics。
CrmConnection
クラスと、ユーザー名とパスワードがas documented in this MSDN articleにハードコードされている接続文字列を使用してCRM Onlineにアクセスできますが、これは私が望むものではありません。現在ログインしているユーザーとして認証します。 https://github.com/azure-samples?query=active-directory
これは私が私が欲しいものを見つけた最も近いのポストですが、それはまだ必要があります。ここでは
は、私は、彼らが他の誰にも便利だ場合に従うことをしようとしてきたサンプルの一部ですユーザー名/パスワード... Using ADAL C# as Confidential User /Daemon Server /Server-to-Server - 401 Unauthorized
"CrmConnectionクラスとこのMSDN記事に記載されているようにハードコードされたユーザー名とパスワードの接続文字列を使用してCRM Onlineにアクセスできますが、これは私が望むものではありません。 " ---> OrganizationServiceProxy(http://stackoverflow.com/questions/37570224/crm-dynamics-2013-how-to-pass-current-logged-as-the-record-owner/37577406#37577406) – dynamicallyCRM
私は、これは間違いですが、これはCRM Onlineには当てはまりません。最新のSDKには含まれていないXrm.Clientライブラリの一部です。 – Equalsk
最初にリンクした例では 'CrmConnection'クラスが必要です。これは' Microsoft.Xrm.Sdk.Client'ライブラリではなく 'Microsoft.Xrm.Client'ライブラリにあります。何か不足していますか?編集:ああ、あなたのコメントを削除しました... – Equalsk