镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

.me access point is broken #544

Closed
Closed

Description

@zhujiaqi

I followed the steps here: https://learn.microsoft.com/en-us/graph/tutorials/python?tabs=aad

and found functions under .me were all broken due to failed replacement of placeholder "me-token-to-replace".

running on mac:

11.7.10

python3.8.9

list of dependencies installed:

ms-identity-python-webapp-master pip freeze
aiohttp==3.9.1
aiosignal==1.3.1
anyio==4.2.0
asgiref==3.7.2
async-timeout==4.0.3
attrs==23.2.0
azure-core==1.29.6
azure-identity==1.15.0
backports.zoneinfo==0.2.1
cachelib==0.10.2
certifi==2023.11.17
cffi==1.16.0
charset-normalizer==3.3.2
click==8.1.7
cryptography==41.0.7
Deprecated==1.2.14
exceptiongroup==1.2.0
Flask==2.2.5
Flask-Session==0.4.1
frozenlist==1.4.1
h11==0.14.0
h2==4.1.0
hpack==4.0.0
httpcore==1.0.2
httpx==0.26.0
hyperframe==6.0.1
identity==0.2.0
idna==3.6
importlib-metadata==6.11.0
importlib-resources==6.1.1
itsdangerous==2.1.2
Jinja2==3.1.2
MarkupSafe==2.1.3
microsoft-kiota-abstractions==1.0.0
microsoft-kiota-authentication-azure==1.0.0
microsoft-kiota-http==1.2.0
microsoft-kiota-serialization-json==1.0.0
microsoft-kiota-serialization-text==1.0.0
msal==1.26.0
msal-extensions==1.1.0
msgraph-core==1.0.0a4
msgraph-sdk==1.0.0
multidict==6.0.4
opentelemetry-api==1.22.0
opentelemetry-sdk==1.22.0
opentelemetry-semantic-conventions==0.43b0
packaging==23.2
pendulum==3.0.0
portalocker==2.8.2
pycparser==2.21
PyJWT==2.8.0
python-dateutil==2.8.2
python-dotenv==0.21.1
requests==2.31.0
six==1.16.0
sniffio==1.3.0
std-uritemplate==0.0.49
time-machine==2.13.0
typing_extensions==4.9.0
tzdata==2023.4
urllib3==2.1.0
Werkzeug==3.0.1
wrapt==1.16.0
yarl==1.9.4
zipp==3.17.0

the traceback:

(venv) ➜ ms-identity-python-webapp-master python try.py
/Users/zhujiaqi/ms-identity-python-webapp-master/venv/lib/python3.8/site-packages/urllib3/init.py:34: NotOpenSSLWarning: urllib3 v2 only supports OpenSSL 1.1.1+, currently the 'ssl' module is compiled with 'LibreSSL 2.8.3'. See: urllib3/urllib3#3020
warnings.warn(
Python Graph Tutorial

To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code xxxx to authenticate.
Traceback (most recent call last):
File "try.py", line 119, in
asyncio.run(main())
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
return future.result()
File "try.py", line 59, in main
await greet_user(graph)
File "try.py", line 96, in greet_user
user = await graph.get_user()
File "try.py", line 46, in get_user
user = await self.user_client.me.get(request_configuration=request_config)
File "/Users/zhujiaqi/ms-identity-python-webapp-master/venv/lib/python3.8/site-packages/msgraph/generated/users/item/user_item_request_builder.py", line 156, in get
return await self.request_adapter.send_async(request_info, User, error_mapping)
File "/Users/zhujiaqi/ms-identity-python-webapp-master/venv/lib/python3.8/site-packages/kiota_http/httpx_request_adapter.py", line 185, in send_async
await self.throw_failed_responses(response, error_map, parent_span, parent_span)
File "/Users/zhujiaqi/ms-identity-python-webapp-master/venv/lib/python3.8/site-packages/kiota_http/httpx_request_adapter.py", line 501, in throw_failed_responses
raise exc
msgraph.generated.models.o_data_errors.o_data_error.ODataError:
APIError
Code: 404
message: None
error: MainError(additional_data={}, code='Request_ResourceNotFound', details=None, inner_error=InnerError(additional_data={'date': DateTime(2024, 1, 8, 11, 39, 25, tzinfo=Timezone('UTC'))}, client_request_id='58c6ed88-363d-444d-a05c-36496c532a8e', date=None, odata_type=None, request_id='58c6ed88-363d-444d-a05c-36496c532a8e'), message="Resource 'me-token-to-replace' does not exist or one of its queried reference-property objects are not present.", target=None)

Activity

  1. shemogumbe commented on Feb 20, 2024

    @shemogumbe
    Contributor

    This is under investigation, In the meantime, you can get the ID of the user you are working with and replace .me with .users.by_user_id(<user-id>)

  2. zhujiaqi commented on Feb 20, 2024

    @zhujiaqi
    Author
  3. shemogumbe commented on Feb 21, 2024

    @shemogumbe
    Contributor

    Notably, the issue is not n the .me access point, I believe it is on the devicecode flow/interactive browser flow.

    This is because, when we have a token, we execute the .me line and get the expected response.

    from msgraph.generated.users.item.user_item_request_builder import UserItemRequestBuilder
    
    graph_scopes = ['https://graph.microsoft.com/.default']
    user_client = GraphServiceClient(credentials=token, scopes=graph_scopes)
    print(f"Clients: {user_client}")
    print(f"Graph Scopes: {graph_scopes}")
    
    
    async def get_my_profile():
        query_params = UserItemRequestBuilder.UserItemRequestBuilderGetQueryParameters(
            select=['displayName', 'mail', 'userPrincipalName'])
    
        request_config = UserItemRequestBuilder.UserItemRequestBuilderGetRequestConfiguration(
            query_parameters=query_params)
        my_profile = await user_client.me.get(request_configuration=request_config)
        print(f"Profile: {my_profile}")
        return await user_client.me.get()
    
    
    asyncio.run(get_my_profile())
    

    Giving a response:

    Clients: <msgraph.graph_service_client.GraphServiceClient object at 0x00000192F156AE30>
    Graph Scopes: ['https://graph.microsoft.com/.default']
    Profile: User(additional_data={'@odata.context': 'https://graph.microsoft.com/v1.0/$metadata#users(displayName,mail,userPrincipalName)/$entity'}, id=None, odata_type='#microsoft.graph.user', deleted_date_time=None, about_me=None, account_enabled=None, activities=None, age_group=None, agreement_acceptances=None, app_role_assignments=None, assigned_licenses=None, assigned_plans=None, authentication=None, authorization_info=None, birthday=None, business_phones=None, calendar=None, calendar_groups=None, calendar_view=None, calendars=None, chats=None, city=None, company_name=None, consent_provided_for_minor=None, contact_folders=None, contacts=None, country=None, created_date_time=None, created_objects=None, creation_type=None, custom_security_attributes=None, department=None, device_enrollment_limit=None, device_management_troubleshooting_events=None, direct_reports=None, display_name='My Name', drive=None, drives=None, employee_experience=None, employee_hire_date=None, employee_id=None, employee_leave_date_time=None, employee_org_data=None, employee_type=None, events=None, extensions=None, external_user_state=None, external_user_state_change_date_time=None, fax_number=None, followed_sites=None, given_name=None, hire_date=None, identities=None, im_addresses=None, inference_classification=None, insights=None, interests=None, is_resource_account=None, job_title=None, joined_teams=None, last_password_change_date_time=None, legal_age_group_classification=None, license_assignment_states=None, license_details=None, mail='xxx@xxx.com', mail_folders=None, mail_nickname=None, mailbox_settings=None, managed_app_registrations=None, managed_devices=None, manager=None, member_of=None, messages=None, mobile_phone=None, my_site=None, oauth2_permission_grants=None, office_location=None, on_premises_distinguished_name=None, on_premises_domain_name=None, on_premises_extension_attributes=None, on_premises_immutable_id=None, on_premises_last_sync_date_time=None, on_premises_provisioning_errors=None, on_premises_sam_account_name=None, on_premises_security_identifier=None, on_premises_sync_enabled=None, on_premises_user_principal_name=None, onenote=None, online_meetings=None, other_mails=None, outlook=None, owned_devices=None, owned_objects=None, password_policies=None, password_profile=None, past_projects=None, people=None, photo=None, photos=None, planner=None, postal_code=None, preferred_data_location=None, preferred_language=None, preferred_name=None, presence=None, print=None, provisioned_plans=None, proxy_addresses=None, registered_devices=None, responsibilities=None, schools=None, scoped_role_member_of=None, security_identifier=None, service_provisioning_errors=None, settings=None, show_in_address_list=None, sign_in_activity=None, sign_in_sessions_valid_from_date_time=None, skills=None, state=None, street_address=None, surname=None, teamwork=None, todo=None, transitive_member_of=None, usage_location=None, user_principal_name='xxx@xxx.com', user_type=None)
    

    Following the path with the device code credential as per the tutorial gave me the same error as you equally got.

    With this, I suggest closing this issue and open an issue to address the device code flow authentication for pats that require delegated permission.

  4. shemogumbe commented on Mar 14, 2024

    @shemogumbe
    Contributor

    Hello Jiaqi Zhu (@zhujiaqi)
    I have isolated this to be an issue with device code credential and how we get token with this, I wil be closing this and creating a task to investigate and fix device code credential flow. Hope this fixes the snippets in the tutorial.
    Delegated permissions via InteractiveBrowser works just fine, not that device code credential takes a dependency on interactive flow at the implementaion.

    The code

    import asyncio
    from datetime import datetime, timedelta
    
    from dotenv import load_dotenv
    
    from azure.identity import InteractiveBrowserCredential
    from msgraph import GraphServiceClient
    from msgraph.generated.users.item.user_item_request_builder import UserItemRequestBuilder
    
    load_dotenv()
    
    scopes = ['User.Read', 'Mail.Read', 'Mail.Send']
    credential = InteractiveBrowserCredential(tenant_id=os.getenv("tenant_id"),
                                              client_id=os.getenv("client_id"),
                                              authority=os.getenv("authority"))
    client = GraphServiceClient(credentials=credential, scopes=scopes)
    async def get_user_profile():
        try:
            # Get the user's profile
            query_params = UserItemRequestBuilder.UserItemRequestBuilderGetQueryParameters(
                select=['displayName', 'mail', 'userPrincipalName'])
            request_config = UserItemRequestBuilder.UserItemRequestBuilderGetRequestConfiguration(
                query_parameters=query_params)
            profile = await client.me.get(request_configuration=request_config)
            print(f"Profile - {profile}")
            my_messages = await client.me.messages.get()
            for message in my_messages.value:
                print(f"message {message.subject}")
        except Exception as e:
            print(e.message)
    asyncio.run(get_user_profile())
    

    and the response is:
    my_profile_and_messages

    The Ticket is in our current sprint and will be fixed by around end of this month

  5. zhujiaqi commented on Mar 14, 2024

    @zhujiaqi
    Author
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions