既定では、Microsoft Graph SDK は、ルート URL を使用して Microsoft Graph REST API にアクセスして https://graph.microsoft.com
、Microsoft Graph グローバル サービス内のデータにアクセスするように構成されています。 開発者はこの構成をオーバーライドして 、Microsoft Graph の国内クラウドデプロイに接続できます。
前提条件
国内クラウドデプロイに接続するように Microsoft Graph SDK を構成するには、次の情報が必要です。
国内クラウドデプロイに接続するには、正しいトークン サービス エンドポイントに接続するように 認証プロバイダー を構成する必要があります。 次に、正しい Microsoft Graph サービス ルート エンドポイントに接続するように SDK クライアントを構成する必要があります。
アクセス許可のスコープ
Microsoft Graph ドメインを .default
含むアクセス許可スコープの値 (スコープを含む) は、国のクラウド展開に Microsoft Graph サービス ルート エンドポイントのドメインを使用する必要があります。 または Mail.Send
などのUser.Read
短縮されたアクセス許可スコープ名も有効です。
-
増分または動的な同意の場合は、
User.Read
https://graph.microsoft.us/User.Read
米国政府 L4 ナショナル クラウドと同等です。
-
静的に定義されたアクセス許可の場合、またはアプリのみのアクセス許可にクライアント資格情報フローを使用している場合は、
https://graph.microsoft.us/.default
正しい.default
スコープ値です。
例
次の例では、Microsoft Graph SDK を使用して 対話型認証プロバイダー を構成し、Microsoft Graph for US Government L4 ナショナル クラウドに接続します。
// Create the InteractiveBrowserCredential using details
// from app registered in the Azure AD for US Government portal
var credential = new InteractiveBrowserCredential(
"YOUR_TENANT_ID",
"YOUR_CLIENT_ID",
new InteractiveBrowserCredentialOptions
{
// https://login.microsoftonline.us
AuthorityHost = AzureAuthorityHosts.AzureGovernment,
RedirectUri = new Uri("YOUR_REDIRECT_URI"),
});
// Create the authentication provider
var authProvider = new AzureIdentityAuthenticationProvider(
credential,
isCaeEnabled: true,
scopes: ["https://graph.microsoft.us/.default"]);
// Create the Microsoft Graph client object using
// the Microsoft Graph for US Government L4 endpoint
// NOTE: The API version must be included in the URL
var graphClient = new GraphServiceClient(
authProvider,
"https://graph.microsoft.us/v1.0");
import (
"github.com/Azure/azure-sdk-for-go/sdk/azcore/cloud"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
graph "github.com/microsoftgraph/msgraph-sdk-go"
auth "github.com/microsoftgraph/msgraph-sdk-go-core/authentication"
)
// Create the InteractiveBrowserCredential using details
// from app registered in the Azure AD for US Government portal
credential, _ := azidentity.NewInteractiveBrowserCredential(
&azidentity.InteractiveBrowserCredentialOptions{
ClientID: "YOUR_CLIENT_ID",
TenantID: "YOUR_TENANT_ID",
ClientOptions: policy.ClientOptions{
// https://login.microsoftonline.us
Cloud: cloud.AzureGovernment,
},
RedirectURL: "YOUR_REDIRECT_URL",
})
// Create the authentication provider
authProvider, _ := auth.NewAzureIdentityAuthenticationProviderWithScopes(credential,
[]string{"https://graph.microsoft.us/.default"})
// Create a request adapter using the auth provider
adapter, _ := graph.NewGraphRequestAdapter(authProvider)
// Set the service root to the
// Microsoft Graph for US Government L4 endpoint
// NOTE: The API version must be included in the URL
adapter.SetBaseUrl("https://graph.microsoft.us/v1.0")
// Create a Graph client using request adapter
graphClient := graph.NewGraphServiceClient(adapter)
// Create the InteractiveBrowserCredential using details
// from app registered in the Azure AD for US Government portal
final InteractiveBrowserCredential credential = new InteractiveBrowserCredentialBuilder()
.clientId("YOUR_CLIENT_ID").tenantId("YOUR_TENANT_ID")
// https://login.microsoftonline.us
.authorityHost(AzureAuthorityHosts.AZURE_GOVERNMENT)
.redirectUrl("YOUR_REDIRECT_URI").build();
final String[] scopes = new String[] {"https://graph.microsoft.us/.default"};
// Create the authentication provider
if (null == scopes || null == credential) {
throw new Exception("Unexpected error");
}
final GraphServiceClient graphClient = new GraphServiceClient(credential, scopes);
// Set the service root to the
// Microsoft Graph for US Government L4 endpoint
// NOTE: The API version must be included in the URL
graphClient.getRequestAdapter().setBaseUrl("https://graph.microsoft.us/v1.0");
$scopes = ['https://graph.microsoft.us/.default'];
// Create the Microsoft Graph client object using
// the Microsoft Graph for US Government L4 endpoint
// $tokenRequestContext is one of the token context classes
// from Microsoft\Kiota\Authentication\Oauth
$graphClient = new GraphServiceClient($tokenRequestContext, $scopes, NationalCloud::US_GOV);
Connect-MgGraph -Environment USGov -ClientId 'YOUR_CLIENT_ID' `
-TenantId 'YOUR_TENANT_ID' -Scopes 'https://graph.microsoft.us/.default'
scopes = ['https://graph.microsoft.us/.default']
credential = InteractiveBrowserCredential(
tenant_id='YOUR_TENANT_ID',
client_id='YOUR_CLIENT_ID',
redirect_uri='YOUR_REDIRECT_URI')
auth_provider = AzureIdentityAuthenticationProvider(credential, scopes=scopes)
# Create the HTTP client using
# the Microsoft Graph for US Government L4 endpoint
http_client = GraphClientFactory.create_with_default_middleware(
host=NationalClouds.US_GOV)
adapter = GraphRequestAdapter(auth_provider, http_client)
graph_client = GraphServiceClient(request_adapter=adapter)
// Create the InteractiveBrowserCredential using details
// from app registered in the Azure AD for US Government portal
const credential = new InteractiveBrowserCredential({
clientId: 'YOUR_CLIENT_ID',
tenantId: 'YOUR_TENANT_ID',
// https://login.microsoftonline.us
authorityHost: AzureAuthorityHosts.AzureGovernment,
redirectUri: 'YOUR_REDIRECT_URI',
});
// Create the authentication provider
const authProvider = new TokenCredentialAuthenticationProvider(credential, {
scopes: ['https://graph.microsoft.us/.default'],
});
// Create the Microsoft Graph client object using
// the Microsoft Graph for US Government L4 endpoint
// NOTE: Do not include the version in the baseUrl
const graphClient = Client.initWithMiddleware({
authProvider: authProvider,
baseUrl: 'https://graph.microsoft.us',
});