Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when trying to list Authentication Methods #2260

Closed
3 tasks done
jermifer opened this issue Dec 18, 2023 · 13 comments · Fixed by microsoftgraph/msgraph-sdk-dotnet-core#789
Closed
3 tasks done

Comments

@jermifer
Copy link

Please provide the following (and please check them off the list with [x]) before submitting this issue:

  • Expected behavior. Please provide links to the specific Microsoft Graph documentation you used to determine the expected behavior.
  • Actual behavior. Provide error codes, stack information, and a Fiddler capture of the request and response (please remove personally identifiable information before posting).
  • Steps to reproduce the behavior. Include your code, IDE versions, client library versions, and any other information that might be helpful to understand your scenario.

I am getting an exception when trying to call graphClient.Users[userPrincipalName].Authentication.Methods.GetAsync()

Expected behavior

Should return a AuthenticationMethodCollectionResponse according to the code insight in Visual Studio. Originally used documentation here: https://learn.microsoft.com/en-us/graph/api/authentication-list-methods?view=graph-rest-1.0&tabs=csharp#examples

Actual behavior

Throws System.MissingMethodException: Method not found: 'System.String Std.UriTemplate.Expand(System.String, System.Collections.Generic.Dictionary`2<System.String,System.Object>)'.

Stack Trace

CCC.HelpDeskPortal.Service.MFAService+<GetAuthenticationMethods>d__6.MoveNext() in C:\repos\ccc.helpdeskportal.Net4.5\CCC.HelpDeskPortal.Service\MFAService.cs:132
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw():12
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task):40
System.Runtime.CompilerServices.TaskAwaiter`1.GetResult():11
 
CCC.HelpDeskPortal.Service.MFAService+<ResetMFA>d__2.MoveNext() in C:\repos\ccc.helpdeskportal.Net4.5\CCC.HelpDeskPortal.Service\MFAService.cs:35
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw():12
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task):40
System.Runtime.CompilerServices.TaskAwaiter`1.GetResult():11
 
CCC.StudentPasswordReset.Web2.Controllers.HomeController+<ResetMFA>d__26.MoveNext() in C:\repos\ccc.helpdeskportal.Net4.5\CCC.StudentPasswordReset.Web2\Controllers\HomeController.cs:338
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw():12
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task):40
System.Web.Mvc.Async.TaskAsyncActionDescriptor.EndExecute(IAsyncResult asyncResult)
System.Web.Mvc.Async.AsyncControllerActionInvoker+<>c__DisplayClass8_0.<BeginInvokeAsynchronousActionMethod>b__1(IAsyncResult asyncResult)
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)
System.Web.Mvc.Async.AsyncControllerActionInvoker+AsyncInvocationWithFilters+<>c__DisplayClass11_0.<InvokeActionMethodFilterAsynchronouslyRecursive>b__0():29
System.Web.Mvc.Async.AsyncControllerActionInvoker+AsyncInvocationWithFilters+<>c__DisplayClass11_2.<InvokeActionMethodFilterAsynchronouslyRecursive>b__2():134
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult)
System.Web.Mvc.Async.AsyncControllerActionInvoker+<>c__DisplayClass3_5.<BeginInvokeAction>b__4()
System.Web.Mvc.Async.AsyncControllerActionInvoker+<>c__DisplayClass3_0.<BeginInvokeAction>b__1(IAsyncResult asyncResult):57
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult)
System.Web.Mvc.Controller+<>c.<BeginExecuteCore>b__152_1(IAsyncResult asyncResult, ExecuteCoreState innerState)
System.Web.Mvc.Async.AsyncResultWrapper+WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult):18
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult)
System.Web.Mvc.Async.AsyncResultWrapper+WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult):18
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult)
System.Web.Mvc.MvcHandler+<>c.<BeginProcessRequest>b__20_1(IAsyncResult asyncResult, ProcessRequestState innerState)
System.Web.Mvc.Async.AsyncResultWrapper+WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult):18
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)
System.Web.HttpApplication+CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute():325
System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step):100
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously):62

Request

GET https://testhelpapps.tri-c.tech/ResetStudentPassword/Home/ResetMFA HTTP/1.1
Host: testhelpapps.tri-c.tech
Connection: keep-alive
sec-ch-ua: "Not_A Brand";v="8", "Chromium";v="120", "Microsoft Edge";v="120"
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "Windows"
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7
Sec-Fetch-Site: none
Sec-Fetch-Mode: navigate
Sec-Fetch-User: ?1
Sec-Fetch-Dest: document
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
Cookie: _spectate_tracking_session=BAh7BkkiE3Zpc2l0b3JfaWRfNTA4BjoGRVRpBGBP2SY%3D--328a5c5e5971d24f788c2c7e05ec7e2aad080878; ASP.NET_SessionId=otdhmtjhb52xc1l4jugkrw54; __utmc=26496824; .AspNet.Cookies=MvdgWjjWXM1mlX1hTffUiv3NZPS95Q1bzxar-8fTYfFBNS6-uUS9_1FcvLRA11yxsyt0dxnusUTJJyAY0KxWnbcE2aMiKZfEgdt01zkkvB9wHQ_uOx9cZn4U08FSbGQ4osdv5yRVsjKDKbHdJntd2C1YnxZMWDQC0wq8U8SFwrVTpGCctD-8Vsh5_693fE_yO32PM6mfa2OQ2EhqxMwBu92rmV-CtYaKauagnfl89WJtU9gsUMTvhjpoWGeSn5UUmf_5TYkvow_Bh3Di2pD8LkkJ5yaWDCEmiKmHXcbhbQlsF6lmWx24remH5GQBnU23; __RequestVerificationToken_L1Jlc2V0U3R1ZGVudFBhc3N3b3Jk0=9Ofiu8rTqYU84HzvXN0FRll_T0klmOJBmAzoXmM78wSMuv9axOF80iU25PKF53xgqasErxSWFcJ5UIYrgE_ZZ5hDsmpY2ostX-YjwdSFYV81; __utma=26496824.1301328716.1686255965.1702922774.1702927160.48; __utmz=26496824.1702927160.48.34.utmcsr=login.microsoftonline.com|utmccn=(referral)|utmcmd=referral|utmcct=/; __utmt=1; __utmb=26496824.6.10.1702927160

Response

HTTP/1.1 302 Found
Cache-Control: private, s-maxage=0
Transfer-Encoding: chunked
Content-Type: text/html; charset=utf-8
Location: /ResetStudentPassword/Error/Error
Server: Microsoft-IIS/10.0
X-AspNetMvc-Version: 5.3
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Mon, 18 Dec 2023 19:27:34 GMT

96
<html><head><title>Object moved</title></head><body>
<h2>Object moved to <a href="/ResetStudentPassword/Error/Error">here</a>.</h2>
</body></html>

0

Steps to reproduce the behavior

I'm working in Microsoft Visual Studio Professional 2022 (64-bit) - Current, Version 17.8.2, but the error occurs on the test server. App is built in .NET Framework 4.8 MVC 5.3. I'm using Microsoft.Graph 5.37.0.0 and Microsoft.Graph.Core 3.1.3.0.

// Multi-tenant apps can use "common",
// single-tenant apps must use the tenant ID from the Azure portal
var clientId = this.secretsService.GetSecret("MSGraphClientID");

// Values from app registration
var tenantId = this.secretsService.GetSecret("MSGraphTenantID");
var fileName = this.secretsService.GetSecret("MSGraphCertFilePath");
var password = this.secretsService.GetSecret("MSGraphCertPassword");

var clientCertificate = new X509Certificate2(fileName, password);

// using Azure.Identity;
var options = new TokenCredentialOptions
{
    AuthorityHost = AzureAuthorityHosts.AzurePublicCloud
};

// https://learn.microsoft.com/dotnet/api/azure.identity.clientcertificatecredential
var credential= new ClientCertificateCredential(
    tenantId, 
    clientId, 
    clientCertificate, 
    options);

var scopes = new[] { "https://graph.microsoft.com/.default" };
var graphClient = new GraphServiceClient(credential, scopes);

AuthenticationMethodCollectionResponse result;

try
{
    result = await graphClient.Users[userPrincipalName].Authentication.Methods.GetAsync();
}
catch (Microsoft.Graph.Models.ODataErrors.ODataError ex)
{
    throw new ApplicationException(ex.Error.Message);
}
catch (Exception ex)
{
    throw ex;
}

@andrueastman
Copy link
Member

Thanks for raising this @jermifer

The baseUrl used in the request does not look correct https://testhelpapps.tri-c.tech/ResetStudentPassword/Home/ResetMFA as the graph client should make a request to a url starting with https://graph.microsoft.com/v1.0.
Any chance you can confirm there is the request shared is correct?

@jermifer
Copy link
Author

Thanks for the quick response.

There is no packet for the Graph call. The capture I provided is from the calling app. The error must be occurring in the library before the code goes out to the API...?

I just noticed, another piece of code that we already have in production (using the older version of the Graph library) is no longer working in test. Same error:

result = await graphClient.Users[userPrincipalName].Authentication.TemporaryAccessPassMethods.PostAsync(requestBody);

I rolled back my changes, and I am still getting the same error, even with the Microsoft.Graph 5.31 and Microsoft.Graph.Core 3.0.11 libraries.

It wasn't until I rolled back to Microsoft.Graph 5.10.0 and Microsoft.Graph.Core 3.0.6 that the TemporaryAccessPassMethods.PostAsync(requestBody); started working again.

@jermifer
Copy link
Author

Just a note: even with TemporaryAccessPassMethods.PostAsync(requestBody); working again, there is no packet for the call to https://graph.microsoft.com/v1.0. Is there some sort of config in Fiddler that I'm missing? I don't have any filters turned on.

@jermifer
Copy link
Author

Upon further inspection, the problem appears to be with the Std.UriTemplate NuGet package. I have tried both versions 0.0.46 and 0.0.49.

In my working code, that package does not exist. Newer versions of Microsoft.Kiota.Abstractions depend on it. In the working code, 1.1.1 is installed. In the broken code, I have tried both 1.7.3 and 1.7.2.

At least, best I can surmise at this point. Hopefully it helps.

@andrueastman
Copy link
Member

Out of curiosity are you able to run the following in the latest version? Any chance the URI has the expected base url?

            var requestInfo = graphClient.Users["user-id"].Authentication.TemporaryAccessPassMethods.ToPostRequestInformation(requestBody);
            Console.WriteLine(requestInfo.URI.OriginalString);

@jermifer
Copy link
Author

Hello,

Trying to run the code you requested throws the same exception.

BTW, I just discovered that Std.UriTemplate 0.0.48 works. 0.0.49 and 0.0.46 do not.

Thanks,

Jen

@GHV393
Copy link

GHV393 commented Dec 20, 2023

Thank You so very much!
I was stuck on this for the last 7 hours, for a contract due before end of week.
The 0.0.48 worked like a charm.

@andrueastman
Copy link
Member

andrueastman commented Dec 21, 2023

Changes between v0.0.48 and v0.0.49 don't seem to point to an issue std-uritemplate/std-uritemplate@v0.0.48...v0.0.49.

Out of curiosity are you specifying the package versions in your csproj? Or does only specifying the package version 0.0.48 seem to resolve the issue?

@GHV393 Any chance you can share your runtime information? Are you also running on net framework 4.8?

@GHV393
Copy link

GHV393 commented Dec 21, 2023

I'm running on Framework 4.6.2. When I changed from 0.0.49 to 0.0.48, I no longer have the issue.

@TriNguyenH
Copy link

I've been struggling with the same issue for hours. Glab to came across this thread, thanks :)

@gronnerup
Copy link

I had the same issue in a .NET 4.8.1 web application when utilizing the MS Graph SDK v5 and trying to fetch the user profile.

Quickly setup a console application which then worked. Checked the version numbers for Std.UriTemplate and Microsoft.Kiota.Authentication.Azure and found that the new console application was running with different version numbers than the web application which was updated to lastest versions.

So try using the following versions:

  • Microsoft.Kiota.Authentication.Azure 0.0.46
  • Microsoft.Kiota.Abstractions 1.7.2

This solved the issue for me.

@dieter-vanderdonckt
Copy link

I had the same problem in a .NET 4.8.1 winforms application using MS Graph 5.37 when fetching MailFolders.
Solved by reversing Std.UriTemplate package from version 0.0.49 to 0.0.48.

@jermifer
Copy link
Author

jermifer commented Jan 2, 2024

Changes between v0.0.48 and v0.0.49 don't seem to point to an issue std-uritemplate/[email protected].

Out of curiosity are you specifying the package versions in your csproj? Or does only specifying the package version 0.0.48 seem to resolve the issue?

@GHV393 Any chance you can share your runtime information? Are you also running on net framework 4.8?

Hello,

I'm not entirely sure about the second part of what you are asking. The csproj file does specify the package version.

I noticed that the Extend method signature for 0.0.48 uses a Dictionary as the second param type, but 0.0.49 uses IReadOnlyDictionary. That seems to be what the code is hung up on (error is "Method not found: 'System.String Std.UriTemplate.Expand(System.String, System.Collections.Generic.Dictionary`2<System.String,System.Object>)'").

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants