Office365-rest-python-client: Acquire_token_for_user 였λ₯˜

에 λ§Œλ“  2019λ…„ 12μ›” 04일  Β·  11μ½”λ©˜νŠΈ  Β·  좜처: vgrem/Office365-REST-Python-Client

μ•ˆλ…•ν•˜μ‹­λ‹ˆκΉŒ,

Office365-REST-Python-Clientλ₯Ό μ‚¬μš©ν•˜μ—¬ μΈνŠΈλΌλ„· Sharepoint 포털에 μ—°κ²°ν•˜λ €κ³  ν–ˆμ§€λ§Œ AuthenticationContext ν΄λž˜μŠ€μ—μ„œ acquire_token_for_user()λ₯Ό ν˜ΈμΆœν•˜λ©΄ μ‹€νŒ¨ν•©λ‹ˆλ‹€.

url = " https://mycompany.sharepoint.com "
ctx_auth = 인증 μ»¨ν…μŠ€νŠΈ(URL)
ctx_auth.acquire_token_for_user("my_username", "my_password")

λ‹€μŒ 였λ₯˜λ₯Ό νŠΈλ¦¬κ±°ν•©λ‹ˆλ‹€.

AttributeError: 'NoneType' κ°œμ²΄μ— 'text' 속성이 μ—†μŠ΅λ‹ˆλ‹€.

λ¬Έμ•ˆ 인사,
ν‘œμ‹œ

question

κ°€μž₯ μœ μš©ν•œ λŒ“κΈ€

μ €μ—κ²Œλ„ νš¨κ³Όκ°€ μžˆμŠ΅λ‹ˆλ‹€. URL은 " https://mycompany.sharepoint.com/sites/AnotherSite " λ˜λŠ” " https://mycompany.sharepoint.com/sites/AnotherSite/Subsite "와 같을 μˆ˜λ„ μžˆμŠ΅λ‹ˆλ‹€.

λŒ€μ‹  λ‹€μŒ μ½”λ“œλ‘œ μ‹œλ„ν•΄ λ³΄μ„Έμš”.

from office365.runtime.auth.authentication_context import AuthenticationContext
from office365.runtime.client_request import ClientRequest
from office365.runtime.utilities.request_options import RequestOptions

user_credentials = {
    'username' : '[email protected]',
    'password' : 'my_password'
}

site_url = "https://mycompany.sharepoint.com/"

ctx_auth = AuthenticationContext(site_url)
if ctx_auth.acquire_token_for_user(user_credentials['username'], user_credentials['password']):
  request = ClientRequest(ctx_auth)
  options = RequestOptions("{0}/_api/web/lists".format(site_url))
  options.set_header('Accept', 'application/json')
  options.set_header('Content-Type', 'application/json')
  data = request.execute_request_direct(options)
  s = json.loads(data.content)

λͺ¨λ“  11 λŒ“κΈ€

λ‚˜λŠ” λ˜‘κ°™μ€ λ¬Έμ œκ°€μžˆλ‹€

λ§ˆμ°¬κ°€μ§€λ‘œ, 이것은 방금 λ‚˜νƒ€λ‚¬μœΌλ©° 더 이상 곡유 지점에 μ•‘μ„ΈμŠ€ν•  수 μ—†μŠ΅λ‹ˆλ‹€.

λ™μΌν•œ λ¬Έμ œκ°€ 있으며 μ—”ν„°ν”„λΌμ΄μ¦ˆ μ…°μ–΄ν¬μΈνŠΈμ— μ•‘μ„ΈμŠ€ν•  수 μ—†μŠ΅λ‹ˆλ‹€. λ‹€λ₯Έ 문제(#76, 2018λ…„ 8μ›” 5일)μ—μ„œ λ‹€μŒ μ†”λ£¨μ…˜μ„ λ³΄μ—¬μ€λ‹ˆλ‹€(아직 μž‘λ™ν•˜μ§€ μ•ŠμŒ).

_ν•΄κ²°λ˜μ—ˆμŠ΅λ‹ˆλ‹€. λ¬Έμ œλŠ” Azure Active Directory와 λ‚΄λΆ€ Active Directory 간에 λΈŒλΌμš°μ €λ₯Ό ν†΅ν•΄μ„œλ§Œ 검사가 μˆ˜ν–‰λ˜λŠ” νšŒμ‚¬ μ‚¬μš©μžμ˜ μ‚¬μš©μ΄μ—ˆμŠ΅λ‹ˆλ‹€. 배치 슀크립트의 경우 ν΄λΌμš°λ“œ AAD에 μ‚¬μš©μžλ₯Ό μƒμ„±ν–ˆμŠ΅λ‹ˆλ‹€._

사싀, λ‚΄ μ‚¬μš©μžκ°€ AAD에 μžˆμ§€λ§Œ μ—¬μ „νžˆ μ•‘μ„ΈμŠ€ν•  수 μ—†μŠ΅λ‹ˆλ‹€.(μ–΄λ–€ μ†”λ£¨μ…˜/λ‹¨μ„œ?

λ‚΄ μ½”λ“œκ°€ μž‘λ™ν•©λ‹ˆλ‹€.
μ‚¬μš©μž 이름 = 'λ‚΄ μ‚¬μš©μž 이름'
λΉ„λ°€λ²ˆν˜Έ = 'λ‚΄ λΉ„λ°€λ²ˆν˜Έ'
ctx_auth.acquire_token_for_user(μ‚¬μš©μž 이름=μ‚¬μš©μž 이름, λΉ„λ°€λ²ˆν˜Έ=passWord)

μ €μ—κ²Œλ„ νš¨κ³Όκ°€ μžˆμŠ΅λ‹ˆλ‹€. URL은 " https://mycompany.sharepoint.com/sites/AnotherSite " λ˜λŠ” " https://mycompany.sharepoint.com/sites/AnotherSite/Subsite "와 같을 μˆ˜λ„ μžˆμŠ΅λ‹ˆλ‹€.

λŒ€μ‹  λ‹€μŒ μ½”λ“œλ‘œ μ‹œλ„ν•΄ λ³΄μ„Έμš”.

from office365.runtime.auth.authentication_context import AuthenticationContext
from office365.runtime.client_request import ClientRequest
from office365.runtime.utilities.request_options import RequestOptions

user_credentials = {
    'username' : '[email protected]',
    'password' : 'my_password'
}

site_url = "https://mycompany.sharepoint.com/"

ctx_auth = AuthenticationContext(site_url)
if ctx_auth.acquire_token_for_user(user_credentials['username'], user_credentials['password']):
  request = ClientRequest(ctx_auth)
  options = RequestOptions("{0}/_api/web/lists".format(site_url))
  options.set_header('Accept', 'application/json')
  options.set_header('Content-Type', 'application/json')
  data = request.execute_request_direct(options)
  s = json.loads(data.content)

이 λ¬Έμ œλŠ” PullRequest #168둜 μˆ˜μ •λ˜μ–΄μ•Ό ν•©λ‹ˆλ‹€.
이제 더 ꡬ체적인 였λ₯˜ λ©”μ‹œμ§€κ°€ ν‘œμ‹œλ©λ‹ˆλ‹€.
인증에 μ‹€νŒ¨ν•  λ•Œλ§ˆλ‹€ 이 νŠΉμ • 였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€.

μ°Έκ³ : μ΅œμ‹  버전 2.1.6-1 둜 μ—…κ·Έλ ˆμ΄λ“œν•΄μ•Ό ν•©λ‹ˆλ‹€.

마크, @KasperSvendsen 및 @fpinab ,

당신이 μ–ΈκΈ‰ ν•œ μ΄ν›„λ‘œ μž‘μ€ μ—…λ°μ΄νŠΈ :

사싀, λ‚˜λŠ” AAD에 λ‚΄ μ‚¬μš©μžκ°€ μžˆμŠ΅λ‹ˆλ‹€

ADFS용 Office 365 Single Sign-On μ‹œλ‚˜λ¦¬μ˜€λ₯Ό μ°Έμ‘°ν•œλ‹€κ³  μƒκ°ν•©λ‹ˆλ‹€. 이 흐름은 μ§€μ›λ˜μ§€ μ•Šμ•˜μœΌλ©° 이것이 제곡된 였λ₯˜κ°€ λ°œμƒν•œ 이유일 수 μžˆμŠ΅λ‹ˆλ‹€.

쒋은 μ†Œμ‹μ€ SharePoint Online을 μ‚¬μš©ν•œ SAML 기반 μ—°ν•© 인증에 λŒ€ν•œ 지원이 2.1.7 λ²„μ „μ—μ„œ λ„μž…λ˜μ—ˆλ‹€λŠ” κ²ƒμž…λ‹ˆλ‹€.

μ „μ œ 쑰건

μ‚¬μš©μžμ— λŒ€ν•œ 닀단계 인증 이 λΉ„ν™œμ„±ν™”λœ κ²ƒμœΌλ‘œ κ°€μ •ν•©λ‹ˆλ‹€.

λ…ΈνŠΈ

μƒˆ 버전이 아직 PyPi에 μΆœμ‹œ λ˜μ§€ μ•Šμ•˜κΈ° λ•Œλ¬Έμ— λ‹€μŒκ³Ό 같이 ν˜„μž¬ GitHubμ—μ„œ μ„€μΉ˜ν•΄μ•Ό ν•©λ‹ˆλ‹€.

핍 μ„€μΉ˜ git+ https://github.com/vgrem/Office365-REST-Python-Client.git

건배,
바딀

@vgrem
ADFS μ‹œλ‚˜λ¦¬μ˜€λ₯Ό μ§€μ›ν•˜κΈ° μœ„ν•΄ μƒˆ λ²„μ „μœΌλ‘œ μ—…λ°μ΄νŠΈν–ˆμŠ΅λ‹ˆλ‹€. ν•˜μ§€λ§Œ μ—¬μ „νžˆ μž‘λ™ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.
μ•„λž˜λŠ” μ½”λ“œ μ˜ˆμž…λ‹ˆλ‹€.

from office365.runtime.auth.authentication_context import AuthenticationContext
account = "[email protected]"
password = "example"
url = "https://example.sharepoint.com/sites/base-dok-testing"

ctx_auth = AuthenticationContext(url)
ctx_auth.acquire_token_for_user(account, password)

μ•„λž˜λŠ” λ‘œκ·Έμž…λ‹ˆλ‹€.

16/Jun/2020 10:18:15] DEBUG [none] [office365.runtime.auth.saml_token_provider.SamlTokenProvider.acquire_token:acquire_token:45] acquire_token called
[16/Jun/2020 10:18:15] DEBUG [none] [office365.runtime.auth.saml_token_provider.SamlTokenProvider.acquire_token:acquire_token:48] Acquiring Access Token..
[16/Jun/2020 10:18:15] DEBUG [none] [urllib3.connectionpool:_new_conn:955] Starting new HTTPS connection (1): login.microsoftonline.com:443
[16/Jun/2020 10:18:16] DEBUG [none] [urllib3.connectionpool:_make_request:428] https://login.microsoftonline.com:443 "POST /GetUserRealm.srf HTTP/1.1" 200 1448
[16/Jun/2020 10:18:16] DEBUG [none] [urllib3.connectionpool:_new_conn:955] Starting new HTTPS connection (1): fs.kerialis.fr:443
[16/Jun/2020 10:18:20] DEBUG [none] [urllib3.connectionpool:_make_request:428] https://fs.kerialis.fr:443 "POST /adfs/services/trust/2005/usernamemixed HTTP/1.1" 200 6542
[16/Jun/2020 10:18:20] DEBUG [none] [urllib3.connectionpool:_new_conn:955] Starting new HTTPS connection (1): login.microsoftonline.com:443
[16/Jun/2020 10:18:21] DEBUG [none] [urllib3.connectionpool:_make_request:428] https://login.microsoftonline.com:443 "POST /rst2.srf HTTP/1.1" 200 3499
[16/Jun/2020 10:18:21] DEBUG [none] [urllib3.connectionpool:_new_conn:955] Starting new HTTPS connection (1): kerialisfr.sharepoint.com:443
[16/Jun/2020 10:18:21] DEBUG [none] [urllib3.connectionpool:_make_request:428] https://kerialisfr.sharepoint.com:443 "HEAD /sites/base-dok-testing/_vti_bin/idcrl.svc HTTP/1.1" 401 0
[16/Jun/2020 10:18:21] ERROR [none] [office365.runtime.auth.saml_token_provider.SamlTokenProvider.acquire_authentication_cookie:acquire_authentication_cookie:208] An error occurred while retrieving auth cookies from https://kerialisfr.sharepoint.com/sites/base-dok-testing/_vti_bin/idcrl.svc

@Simplici , v2.1.8 λ˜λŠ” κ·Έ 이후 버전이 κ·€ν•˜μ˜ νŽΈμ—μ„œ ν™œμš©λ˜κ³  μžˆλ‹€κ³  ν™•μ‹  ν•˜μ‹­λ‹ˆκΉŒ?

그렇지 μ•ŠμœΌλ©΄ μ—¬κΈ° 에 보고된 것과 λ™μΌν•œ λ¬Έμ œκ°€ λ°œμƒν•  수

@vgrem λ‚˜λŠ”

μ΅œμ‹  릴리슀 2.1.9둜 μ—…λ°μ΄νŠΈν•΄λ„ κ²°κ³ΌλŠ” λ™μΌν•©λ‹ˆλ‹€.

λ‚΄ λ™λ£Œκ°€ 일뢀 μˆ˜μ •ν•œ λ‹€μŒ μž‘λ™ν•©λ‹ˆλ‹€: https://github.com/vgrem/Office365-REST-Python-Client/issues/210.

@vgrem 같은 λ¬Έμ œκ°€ μžˆμŠ΅λ‹ˆλ‹€. μ•„λž˜ μ½”λ“œλŠ” " https://company.sharepoint.com/_vti_bin/idcrl.svc μ—μ„œ 인증 μΏ ν‚€λ₯Ό κ²€μƒ‰ν•˜λŠ” λ™μ•ˆ 였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€" 였λ₯˜λ₯Ό λ°˜ν™˜ν•©λ‹ˆλ‹€.

2.1.7.post1도 μ„€μΉ˜ν–ˆμ§€λ§Œ 닀단계 인증을 확인할 κ΄€λ¦¬μž μ•‘μ„ΈμŠ€ κΆŒν•œμ΄ μ—†μŠ΅λ‹ˆλ‹€.

office365.runtime.auth.authentication_contextμ—μ„œ 인증 μ»¨ν…μŠ€νŠΈ κ°€μ Έμ˜€κΈ°
office365.sharepoint.client_contextμ—μ„œ ClientContext κ°€μ Έμ˜€κΈ°
office365.sharepoint.fileμ—μ„œ 파일 κ°€μ Έμ˜€κΈ°

URL = ' https://company.sharepoint.com '
μ‚¬μš©μž 이름 = ' [email protected] '
λΉ„λ°€λ²ˆν˜Έ = 'xxx'

ctx_auth = 인증 μ»¨ν…μŠ€νŠΈ(URL)

ctx_auth.acquire_token_for_user(μ‚¬μš©μž 이름, λΉ„λ°€λ²ˆν˜Έ)인 경우:
ctx = ClientContext(URL, ctx_auth)
μ›Ή = ctx.web
...

이 νŽ˜μ΄μ§€κ°€ 도움이 λ˜μ—ˆλ‚˜μš”?
0 / 5 - 0 λ“±κΈ‰