다음을 통해 공유


Python을 사용하여 Azure Data Lake Storage Gen1로 최종 사용자 인증

이 문서에서는 Python SDK를 사용하여 Azure Data Lake Storage Gen1에서 최종 사용자 인증을 수행하는 방법에 대해 알아봅니다. 최종 사용자 인증은 두 가지 범주로 더 분할될 수 있습니다.

  • 다단계 인증이 없는 최종 사용자 인증
  • 다단계 인증을 사용한 최종 사용자 인증

이 문서에서는 이러한 옵션에 대해 설명합니다. Python을 사용하여 Data Lake Storage Gen1로 서비스 간 인증을 보려면 Python 을 사용하여 Data Lake Storage Gen1로 서비스 간 인증을 참조하세요.

필수 조건

모듈 설치

Python을 통해 Data Lake Storage Gen1을 사용하려면 세 가지 모듈을 설치해야 합니다.

다음 명령을 사용하여 모듈을 설치합니다.

pip install azure-mgmt-resource
pip install azure-mgmt-datalake-store
pip install azure-datalake-store

새 Python 애플리케이션 만들기

  1. 선택한 IDE에서 새 Python 애플리케이션을 만듭니다(예 mysample.py: .).

  2. 다음 코드 조각을 추가하여 필요한 모듈을 가져옵니다.

    ## Use this for Azure AD authentication
    from msrestazure.azure_active_directory import AADTokenCredentials
    
    ## Required for Azure Data Lake Storage Gen1 account management
    from azure.mgmt.datalake.store import DataLakeStoreAccountManagementClient
    from azure.mgmt.datalake.store.models import DataLakeStoreAccount
    
    ## Required for Azure Data Lake Storage Gen1 filesystem management
    from azure.datalake.store import core, lib, multithread
    
     # Common Azure imports
     import adal
     from azure.mgmt.resource.resources import ResourceManagementClient
     from azure.mgmt.resource.resources.models import ResourceGroup
    
     ## Use these as needed for your application
     import logging, pprint, uuid, time
    
  3. 에 변경 내용을 저장합니다 mysample.py.

다단계 인증을 사용한 최종 사용자 인증

계정 관리의 경우

다음 코드 조각을 사용하여 Data Lake Storage Gen1 계정의 계정 관리 작업을 위해 Microsoft Entra ID로 인증합니다. 다음 코드 조각은 다단계 인증을 사용하여 애플리케이션을 인증하는 데 사용할 수 있습니다. 기존 Microsoft Entra ID 네이티브 애플리케이션에 대한 아래 값을 제공합니다.

authority_host_url = "https://login.microsoftonline.com"
tenant = "FILL-IN-HERE"
authority_url = authority_host_url + '/' + tenant
client_id = 'FILL-IN-HERE'
redirect = 'urn:ietf:wg:oauth:2.0:oob'
RESOURCE = 'https://management.core.windows.net/'

context = adal.AuthenticationContext(authority_url)
code = context.acquire_user_code(RESOURCE, client_id)
print(code['message'])
mgmt_token = context.acquire_token_with_device_code(RESOURCE, code, client_id)
armCreds = AADTokenCredentials(mgmt_token, client_id, resource = RESOURCE)

파일 시스템 작업의 경우

Data Lake Storage Gen1 계정의 파일 시스템 작업에 대해 Microsoft Entra ID로 인증하려면 이 기능을 사용합니다. 다음 코드 조각은 다단계 인증을 사용하여 애플리케이션을 인증하는 데 사용할 수 있습니다. 기존 Microsoft Entra ID 네이티브 애플리케이션에 대한 아래 값을 제공합니다.

adlCreds = lib.auth(tenant_id='FILL-IN-HERE', resource = 'https://datalake.azure.net/')

다단계 인증이 없는 최종 사용자 인증

더 이상 사용되지 않습니다. 자세한 내용은 Python SDK를 사용하는 Azure 인증을 참조하세요.

다음 단계

이 문서에서는 최종 사용자 인증을 사용하여 Python을 사용하여 Azure Data Lake Storage Gen1로 인증하는 방법을 알아보았습니다. 이제 Python을 사용하여 Azure Data Lake Storage Gen1로 작업하는 방법에 대해 설명한 다음 문서를 확인할 수 있습니다.