2017-06-14 10 views
1

インターネット上で匿名アクセスが可能なSharePoint公開サイトがあります。最新の要件を満たすためには、ユーザーログイン(AzureAD、マイクロソフトの個人アカウントと職場アカウントなど)を実装する必要があります。Azureアクティブディレクトリv2.0 SharePointサイトでのWeb API統合のクエリ

https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-v2-flows

は、ここではドキュメントごととして、私たちは、データベースからのセキュアな情報を取得するには、この使用してWeb APIを実装したいです。 MSAL.jsファイルをSharePoint上でユーザーのログインとログアウトに使用することを考えています。ベアラトークンを取得した後、データベースから追​​加データ用のWeb APIを呼び出すことができます。

スタンドアロンのWeb APIの制限:「あなたはOAuth 2.0ので保護されたWeb APIを構築するためにバージョン2.0のエンドポイントを使用することができます。ただし、Web APIは、同じアプリケーションIDを持つアプリケーションからのみトークンを受け取ることができます。別のアプリケーションIDを持つクライアントからWeb APIにアクセスすることはできません。クライアントは、Web APIへのアクセス権を要求したり、取得することはできません。」

どのように我々はApp Registration Portalで同じアプリケーションIDを持つ2つのアプリケーションを作成することができますか?または、SharePointとWeb APIの最後で同じアプリケーションIDを使用する必要がありますか? 2つのアプリケーションを登録する必要はありません

答えて

0

は、あなただけの1つのレジスタのアプリケーションに必要です。

<script class="pre"> 
    var userAgentApplication = new Msal.UserAgentApplication("e5e5f2d3-4f6a-461d-b515-efd11d50c338", null, function (errorDes, token, error, tokenType) { 
     // this callback is called after loginRedirect OR acquireTokenRedirect (not used for loginPopup/aquireTokenPopup) 
    }) 
    userAgentApplication.loginPopup(["user.read"]).then(function (token) { 
     var user = userAgentApplication.getUser(); 
     console.log(token); 
     // signin successful 
    }, function (error) { 
     // handle error 
    }); 
</script> 

とWeb APIを保護するために、あなたは同じアプリを使用することができますし、以下のコードを参照してください:あなたがアプリケーションを登録した後は、Web APIを呼び出すためにトークンを取得するには、以下のMSALライブラリを使用してすることができます

public void ConfigureAuth(IAppBuilder app) 
{ 
    var tvps = new TokenValidationParameters 
    { 
     // The web app and the service are sharing the same clientId 
     ValidAudience = "e5e5f2d3-4f6a-461d-b515-efd11d50c338", 
     ValidateIssuer = false, 
    }; 

    // NOTE: The usual WindowsAzureActiveDirectoryBearerAuthenticaitonMiddleware uses a 
    // metadata endpoint which is not supported by the v2.0 endpoint. Instead, this 
    // OpenIdConenctCachingSecurityTokenProvider can be used to fetch & use the OpenIdConnect 
    // metadata document. 

    app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions 
    { 
     AccessTokenFormat = new JwtFormat(tvps, new OpenIdConnectCachingSecurityTokenProvider("https://login.microsoftonline.com/common/v2.0/.well-known/openid-configuration")), 
    }); 
} 
関連する問題