Microsoft Graph snippets sample for ASP.NET Core 3.1 - Authentication error - asp.net-core

As far as I know I have followed the instructions for setting up the Microsoft Graph sample https://github.com/microsoftgraph/aspnet-snippets-sample, including joining the Microsoft 365 Developer Program. However when I run the sample and attempt to log in with my new Developer Program user I get the following error message:
Authentication error "Value cannot be null. (Parameter 'value')"
The error us being caught in this routine:
options.Events.OnAuthenticationFailed = context => {
var error = WebUtility.UrlEncode(context.Exception.Message);
context.Response
.Redirect($"/Home/ErrorWithMessage?message=Authentication+error&debug={error}");
context.HandleResponse();
return Task.FromResult(0);
};
If I log in with my personal Microsoft account then everything works fine, so I'm guessing this has something to do with my Developer Program account. The error message isn't very helpful and there not stack trace to speak of. I've tried using Fiddler to see if there's any more information but with no luck either. Any ideas about what I might be doing wrong?

Tested and reproduced the issue. You are getting this error because, as you have created application in one tenant and accessing the application with the Developer Program account(another tenant).
The Solution would be provide Provision for the application (service principal creation) Consent the application with the developer Program account(needs to be admin) if you want to use the application in developer tenant and Please below call
https://login.microsoftonline.com/common/oauth2/authorize?response_type=code&client_id=id&redirect_uri=https%3A%2F%2Flocalhost%3A44307%2F&prompt=admin_consent

After looking at the error messages in the output from the Kestrel web server I discovered that the line causing the problem was this one:
identity.AddClaim(new Claim(GraphClaimTypes.TimeZone, user.MailboxSettings.TimeZone));
and it was because the value of user.MailboxSettings.TimeZone was null. Once I set up a TimeZone in my developer account then everything works fine.

Related

WebSocket4Net in SilverLight

I am trying to create a WebSocket client through WebSocket4Net with port 4503.However i could see the the WebSocket status only as "Connecting" as it is neither raising any exceptions nor proceeding further.I was able to throw the Exception OnError Event which states that
"An attempt was made to access a socket in a way forbidden by its access permissions"
Am i missing anything?. Any suggestions or link will be much helpful.Thanks in advance.
ws = new WebSocket("ws://localhost:4503/WSServer");
ws.Opened += new EventHandler<EventArgs>(ws_Opened);
ws.Open();
I've been getting this kind of error today with a different type of socket library. This may be an access permissions problem in Silverlight, but on the server side, I found that I had to shut down Visual Studio, and then launch it with admin permissions in order to start up the service. It's going to be something like that. If it is a Silverlight access permissions thing, you will want to try running it out of browser and turning on elevated trust.

The request failed with HTTP status 401: Access Denied

I am new to Vb.net. I am creating an intranet application which needs the windows loginname. I got the login name from System.Net.CredentialCache.DefaultNetworkCredentials. It worked fine in my localhost machine. But the problem is that when I am trying to access the site from Development server it is showing the error:
The request failed with HTTP status 401: Access Denied
But the same code is working fine in Test environment.I don't have any idea why these both environment behaving differently.
I am using windows Integrated authentication and Anonymous access disabled. Please help me to figure out this issue.
Dim consumeWebService As ws-ProfileService
consumeWebService = New ws-ProfileService
consumeWebService.PreAuthenticate = True
consumeWebService.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials
Thanks in advance.
It sounds like an impersonation issue. Have a read here and see if this helps. It's definitely worth the read even if seven years old.
How To: Use Impersonation and Delegation in ASP.NET 2.0

WP7 error: "The remote server returned an error: NotFound."

I have this code that it used to work, but at some specific time it stopped to work and returned the error "The remote server returned an error: NotFound."
WebClient deliciousWebClient = new WebClient();
deliciousWebClient.Credentials = Credentials;
deliciousWebClient.DownloadStringAsync(new Uri("https://api.del.icio.us/v1/tags/get"));
deliciousWebClient.DownloadStringCompleted += (s, ee) =>
{
if (ee.Error == null)
{
…
Any suggestion on this error?
In this code, the error is pointing to delicious endpoit, but the same error is happening with some other services...
The NotFound error is a classic 404 error, so it's possible that the API endpoint is down or that it changed on you.
I'd start by using Fiddler2 to make the requests manually. That'll help you figure out whether the issue is in your code somewhere or on the API side.
It's hard to get Fiddler working with the WP7 emulator, as you noted below. One trick I've used in the past when I got really desperate was to write a quick console app that used the same code that my Windows Phone app was executing. Then I was able to successfully intercept the traffic. It turned out that my request being properly formatted.

Error 404 - file not found on Silverlight RIA service call

I have search everywhere for a solution to my problem, but I am not able to find one. I have built a Silverlight 4 Navigation app, and am using RIA Services to process a custom entity (which is essentially running server-side calls to COM dlls). In my debug environment, everything works fine, but when I try to deploy to IIS7 (on the development machine) as a website, it gives me the following error when calling the Get query on the entity:
Load operation failed for query 'GetNewHWCoil'. The remote server returned an error: NotFound.
at System.ServiceModel.DomainServices.Client.OperationBase.Complete(Exception error)
at System.ServiceModel.DomainServices.Client.LoadOperation.Complete(Exception error)
at System.ServiceModel.DomainServices.Client.DomainContext.CompleteLoad(IAsyncResult asyncResult)
at System.ServiceModel.DomainServices.Client.DomainContext.<>c__DisplayClass1b.<Load>b__17(Object )
Everything I found online says to check the Authentication area on IIS and make sure that it is set only to Anonymous Authentication, which it is. And they also say to enable WCF logging, which when I add the necessary text to the web.config file, I still don't get any logs. They also say to use Fiddler2 to trace the HTTP calls, but I only get a 404 error on there with the textview giving me the standard IIS file not found website. I cannot figure out how to debug this problem.
The Silverlight app needs to make calls to a set of 3rd party COM dlls to calculate the performace of water coils. Since I do not want to have the app run OOB, (this will negate the whole point of it being a web app instead of a WPF app) I have the ASP.net project interacting with the dlls using the custom entities.
The function (or Query as RIA services calls it) GetNewHWCoil is located in the DomainService class and uses this code:
Public Function GetNewHWCoil() as HWCoil 'HWCoil is a custom object
If bRanCalc then 'bRanCalc is a global boolean variable that gets set to true if the calc call on the dlls have been made
Return mHWCoil 'global copy of the calculated coil object
bRanCalc = False
else
Return New HWCoil
end if
End Function
The error runs before any calculation should be called, so it is assumed that it is erroring on the 'Return New HWCoil' part.
Any help on this would be appreciated.
Thanks,
Chris
I found the solution to my problem. I fonud out that I can have VS run the debug from IIS, and when I had it create the virtual directory it told me I needed to install ASP.NET 4 on the server. I thought that by checking the ASP.NET checkbox in the Add Windows Features dialog that I had already done that. But it only installed .NET 2 version. So after looking online for this new problem, I found that I needed to run the command
C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis -i
and everything worked fine after that.
Chris

Silverlight client load operation failed for query "Login". [GenericParameterNotValid]

I have one user who gets the following error when trying to login, "Silverlight client load operation failed for query "Login". [GenericParameterNotValid]". The odd thing is that other users are able to login without issue and I can login using the "problem" account from other machines.
At this point I think it's got to be a client side configuration issue.
My next step is to confirm the Client Side Silverlight Version, but I don't know where to go after that.
Do you have any suggestions?
Install Silverlight Developer runtime on the client to get more details on the error.
Try deleting the user's profile.
This thread might help you.
Just leaving a breadcrumb here. We had the following error in a Silverlight RIA Services application attempting to login:
Load operation failed for query 'Login'. Error in deserializing body of the request message for the operation 'Login'. The OperationFormatter could not deserialize any information from the Message because the Message is empty (IsEmpty = true).
This was in Server 2003 with IE 8. Turns out a restart of the browser made the problem go away! Very frustrating.