디먼 애플리케이션은 위임된 권한 대신 애플리케이션 권한을 사용합니다. 따라서 지원되는 계정 유형은 조직 디렉터리 또는 개인 Microsoft 계정(예: Skype, Xbox, Outlook.com)의 계정이 될 수 없습니다. Microsoft 개인 계정의 디먼 애플리케이션에 대한 동의 권한을 부여하는 테넌트 관리자가 없습니다. 내 조직의 계정 또는 모든 조직의 계정을 선택해야 합니다.
애플리케이션 구성에 지정된 권한은 테넌트로 지정(조직에 연결된 테넌트 ID 또는 도메인 이름을 지정)해야 합니다.
다중 테넌트 도구를 제공하려는 경우에도 서비스가 사용해야 하는 테넌트를 안정적으로 유추할 수 없으므로 이 흐름이 아닌common 테넌트 ID 또는 organizations 도메인 이름을 사용해야 합니다.
{
"AzureAd": {
"Instance": "https://login.microsoftonline.com/",
"TenantId": "[Enter here the tenantID or domain name for your Azure AD tenant]",
"ClientId": "[Enter here the ClientId for your application]",
"ClientCredentials": [
{
"SourceType": "ClientSecret",
"ClientSecret": "[Enter here a client secret for your application]"
}
]
}
}
# Credentials
TENANT_ID=Enter_the_Tenant_Info_Here
CLIENT_ID=Enter_the_Application_Id_Here
// You provide either a ClientSecret or a CertificateConfiguration, or a ClientAssertion. These settings are exclusive
CLIENT_SECRET=Enter_the_Client_Secret_Here
CERTIFICATE_THUMBPRINT=Enter_the_certificate_thumbprint_Here
CERTIFICATE_PRIVATE_KEY=Enter_the_certificate_private_key_Here
CLIENT_ASSERTION=Enter_the_Assertion_String_Here
# Endpoints
// the Azure AD endpoint is the authority endpoint for token issuance
AAD_ENDPOINT=Enter_the_Cloud_Instance_Id_Here // https://login.microsoftonline.com/
// the graph endpoint is the application ID URI of Microsoft Graph
GRAPH_ENDPOINT=Enter_the_Graph_Endpoint_Here // https://graph.microsoft.com/
{
"authority": "https://login.microsoftonline.com/<your_tenant_id>",
"client_id": "your_client_id",
"scope": [ "https://graph.microsoft.com/.default" ],
"secret": "The secret generated by Azure AD during your confidential app registration",
"endpoint": "https://graph.microsoft.com/v1.0/users"
}
{
"authority": "https://login.microsoftonline.com/<your_tenant_id>",
"client_id": "your_client_id",
"scope": [ "https://graph.microsoft.com/.default" ],
"thumbprint": "790E... The thumbprint generated by Azure AD when you upload your public cert",
"private_key_file": "server.pem",
"endpoint": "https://graph.microsoft.com/v1.0/users"
}
{
"Instance": "https://login.microsoftonline.com/{0}",
"Tenant": "[Enter here the tenantID or domain name for your Azure AD tenant]",
"ClientId": "[Enter here the ClientId for your application]",
"ClientSecret": "[Enter here a client secret for your application]",
"CertificateName": "[Or instead of client secret: Enter here the name of a certificate (from the user cert store) as registered with your application]"
}
ClientSecret 또는 CertificateName을 제공합니다. 해당 설정은 배타적입니다.
MSAL 애플리케이션 인스턴스화
MSAL 애플리케이션을 인스턴스화하려면 해당 언어에 따라 MSAL 패키지를 추가, 참조하거나 가져옵니다.
클라이언트 암호 또는 인증서(또는 고급 시나리오로 서명된 어설션)를 사용하는지에 따라 구성이 달라집니다.
class Program
{
static async Task Main(string[] _)
{
// Get the Token acquirer factory instance. By default it reads an appsettings.json
// file if it exists in the same folder as the app (make sure that the
// "Copy to Output Directory" property of the appsettings.json file is "Copy if newer").
TokenAcquirerFactory tokenAcquirerFactory = TokenAcquirerFactory.GetDefaultInstance();
// Configure the application options to be read from the configuration
// and add the services you need (Graph, token cache)
IServiceCollection services = tokenAcquirerFactory.Services;
services.AddMicrosoftGraph();
// By default, you get an in-memory token cache.
// For more token cache serialization options, see https://aka.ms/msal-net-token-cache-serialization
// Resolve the dependency injection.
var serviceProvider = tokenAcquirerFactory.Build();
// ...
}
}
# Pass the parameters.json file as an argument to this Python script. E.g.: python your_py_file.py parameters.json
config = json.load(open(sys.argv[1]))
# Create a preferably long-lived app instance that maintains a token cache.
app = msal.ConfidentialClientApplication(
config["client_id"], authority=config["authority"],
client_credential=config["secret"],
# token_cache=... # Default cache is in memory only.
# You can learn how to use SerializableTokenCache from
# https://msal-python.rtfd.io/en/latest/#msal.SerializableTokenCache
)
Authority는 클라우드 인스턴스와 테넌트 ID의 연결입니다. 예를 들면 https://login.microsoftonline.com/contoso.onmicrosoft.com 또는 https://login.microsoftonline.com/aaaabbbb-0000-cccc-1111-dddd2222eeee입니다. 구성 파일 섹션에 표시된 appsettings.json 파일에서 인스턴스와 테넌트는 각각 Instance 및 Tenant 값으로 표시됩니다.
코드 자체는 완전히 동일합니다. 인증서는 구성에 설명되어 있습니다.
인증서를 가져오는 방법에는 여러 가지가 있습니다. 자세한 내용은 https://aka.ms/ms-id-web-certificates를 참조하세요.
KeyVault에서 인증서를 가져오는 방법은 다음과 같습니다. Microsoft ID는 Azure ID의 DefaultAzureCredential에 위임하고 KeyVault에서 인증서에 액세스할 수 있는 경우 관리 ID를 사용했습니다. 애플리케이션은 개발자 자격 증명을 사용하므로 로컬로 디버그할 수 있습니다.
# Pass the parameters.json file as an argument to this Python script. E.g.: python your_py_file.py parameters.json
config = json.load(open(sys.argv[1]))
# Create a preferably long-lived app instance that maintains a token cache.
app = msal.ConfidentialClientApplication(
config["client_id"], authority=config["authority"],
client_credential={"thumbprint": config["thumbprint"], "private_key": open(config['private_key_file']).read()},
# token_cache=... # Default cache is in memory only.
# You can learn how to use SerializableTokenCache from
# https://msal-python.rtfd.io/en/latest/#msal.SerializableTokenCache
)
MSAL Python에서 이 ConfidentialClientApplication의 개인 키로 서명되는 클레임을 사용하여 클라이언트 클레임을 제공할 수 있습니다.
# Pass the parameters.json file as an argument to this Python script. E.g.: python your_py_file.py parameters.json
config = json.load(open(sys.argv[1]))
# Create a preferably long-lived app instance that maintains a token cache.
app = msal.ConfidentialClientApplication(
config["client_id"], authority=config["authority"],
client_credential={"thumbprint": config["thumbprint"], "private_key": open(config['private_key_file']).read()},
client_claims = {"client_ip": "x.x.x.x"}
# token_cache=... # Default cache is in memory only.
# You can learn how to use SerializableTokenCache from
# https://msal-python.rtfd.io/en/latest/#msal.SerializableTokenCache
)