microsoftgraph / microsoftgraph/msgraph-sdk-dotnet

GraphClient fail to fetch User if UPN start with $(dollar sign)

Open
#2,635 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Needs: Attention :wave: type:bug
Dominant language
C#
Stars
789
Forks
264
Avg merge
15h 17m
Merged PRs (30d)
3

Description

Describe the bug

Based on the userPrincipalName section of this documentation, An UPN starts with $ (dollar sign) is a valid UPN. However, if we pass in a UPN starting with $, we would get an error saying:

Microsoft.Graph.Models.ODataErrors.ODataError: The request URI is not valid. Since the segment 'users' refers to a collection, this must be the last segment in the request URI or it must be followed by an function or action that can be bound to it otherwise all intermediate segments must refer to a single resource.
Expected behavior

If the UPN is valid, we should be able to get the user without any error.

How to reproduce

Using the code below:

var upn = "$abc@def.com";

User user = await graphClient
  .Users[upn]
  .GetAsync(requestConfiguration =>
  {
      requestConfiguration.QueryParameters.Select = new string[] { "id", "UserPrincipalName" };
  })
  .ConfigureAwait(false);

we can also trigger the same error (link) in the Graph Explorer playground.

SDK Version

5.46.0

Latest version known to work for scenario above?

No response

Known Workarounds

N/A
Previously we called Graph with HTTP Client and HttpUtility.UrlEncode(upn) works. However, because the Graph SDK 5.0 is doing the encoding, double encoding would only make the problem worse.

Debug output

No response

Configuration

No response

Other information

Based on this thread, it is a known feature when calling the Graph API. we have different API syntax for UPN starting with $.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the provided C# reproduction using GraphClient.Users[upn].GetAsync and inspect the request URI produced for a UPN beginning with $. Compare it with the working HttpClient and UrlEncode behavior described in the issue. Done means a valid dollar-prefixed UPN can be fetched without the reported URI error.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.