403:forbidden when reading mails from Exchange online using Microsoft.Graph - asp.net

I have read emails from Exchange online in c#.net using Office 365 API, but getting some issue on response object
(HttpResponseMessage response = await client.SendAsync(request))
i.e
{StatusCode: 403, ReasonPhrase: 'Forbidden', Version: 1.1, Content:
System.Net.Http.StreamContent, Headers:
{
Transfer-Encoding: chunked
request-id: a0983ea5-313d-4234-b1c6-249f3359c71c
client-request-id: a0983ea5-313d-4234-b1c6-249f3359c71c
x-ms-ags-diagnostic: {"ServerInfo":{"DataCenter":"SouthEast
Asia","Slice":"SliceB","ScaleUnit":"002","Host":"AGSFE_IN_3","ADSiteName":"SIN"}
}
OutBoundDuration: 906.2963
Duration: 1177.9769
Cache-Control: private
Date: Wed, 23 Dec 2015 12:08:42 GMT
Server: Microsoft-IIS/8.5
X-Powered-By: ASP.NET
Content-Type: application/json
}}
For more information :
Please refer this link : http://dev.office.com/getting- started/office365apis
Provide required information login,app name etc.
Download app and run your system
In run time ,error occurred on response object
So Please tell me how to fixed it and let me know if any information required.
Please help me out.
Thanks,
Sheena

You have to register your application on Azure Active Directory (AAD) and set the application permissions to read emails in your app registration.
Check out this presentations starting fromr slide #24:
http://www.mostafaelzoghbi.com/2015/10/identity-and-office-365-presentation-on.html
Hope this helps.

Exchange mailbox access by API was disabled for that account. Please follow https://msdn.microsoft.com/en-us/library/office/dn467892(v=exchg.150).aspx to enable it, e.g. Set-CASMailbox –Identity adam#contoso.com -EwsEnabled:$true

Related

Cognitive Services Custom Vision SDK NotFound Error

I'm experiencing a strange behavior. Got a Custom Vision service deployed on Azure. It contains a single project with no published models.
Using the HTTP REST Api and querying for projects, it correctly returns a list of (one) projects as shown below:
GET https://westeurope.api.cognitive.microsoft.com/customvision/v3.0/training/projects HTTP/1.1
Host: westeurope.api.cognitive.microsoft.com
Training-Key: {MY_TRAINING_APIKEY}
apim-request-id: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
x-content-type-options: nosniff
Date: Thu, 02 May 2019 18:57:25 GMT
Content-Length: 605
Content-Type: application/json; charset=utf-8
[{
PROJECT_DATA
}]
But, if I try to use the service via C# SDK using:
Microsoft.Azure.CognitiveServices.Vision.CustomVision.Prediction
Microsoft.Azure.CognitiveServices.Vision.CustomVision.Training
both 1.0 version, every time I got:
Microsoft.Azure.CognitiveServices.Vision.CustomVision.Training.Models.CustomVisionErrorException:
'Operation returned an invalid status code 'NotFound''
This is the code snippet using the SDK.
using (CustomVisionTrainingClient client = new CustomVisionTrainingClient())
{
client.ApiKey = "{MY_TRAINING_APIKEY}";
client.Endpoint = "https://westeurope.api.cognitive.microsoft.com/customvision/v3.0/Training/";
var projects = client.GetProjects();
}
Interesting fact: trying to use both Training and Prediction clients on currently working Custom Vision project (with deployed models too) I keep getting NotFound error on every SDK method.
Am I missing something?
Thanks in advance.
Fabio.
For CognitiveServices Vision clients, you need to provide the base URI as the Endpoint property, not the entire API endpoint. The client SDK itself will add the remainder of the path (including the version) depending on the method you call.
So in your case you need to do the following:
using (CustomVisionTrainingClient client = new CustomVisionTrainingClient())
{
client.ApiKey = "{MY_TRAINING_APIKEY}";
client.Endpoint = "https://westeurope.api.cognitive.microsoft.com";
var projects = client.GetProjects();
}

ASP.Net Core - OAuth token endpoint failure: Status: BadRequest

When using ASP.Net Core's authentication for Google, I'm performing the following scenario:
Click to login via Google.
Log into Google successfully. At this point I am returned back to my application and I am able to move on my with process. The user claims were returned as expected.
Immediately go back to step 1 and try to login via Google again with the same account. If prompted at Google, select the same account/enter the credentials again.
At this point I now receive the below error.
If I wait a period of time, perhaps 30 minutes, if I start at step 1 again, I don't encounter the issue until I again reach step 4. If I restart my IIS ApplicationPool for my Core project, I can follow the above scenario where step 1 works, but then step 4 shows the issue.
I have searched what feels like endlessly online to no avail. Does anyone have anything they can suggest? Why would this work the first time, and then fail on second, third attempts?
I'm receiving the below error when following the scenario above on my Google Pixel 3 XL phone:
System.Exception:
SocialLoginController|Error|OAuth
token endpoint failure: Status: BadRequest;Headers: Vary: X-Origin,
Referer, Origin,Accept-Encoding Date: Sun, 03 Mar 2019 09:35:45 GMT
Server: ESF Cache-Control: private X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN X-Content-Type-Options: nosniff
Alt-Svc: quic=":443"; ma=2592000; v="44,43,39" Accept-Ranges: none
Transfer-Encoding: chunked ;Body: { "error": "invalid_grant",
"error_description": "Bad Request" };
The code in my Startup.cs class for Google's authentication is as follows:
services.AddAuthentication(options =>
{
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
})
.AddCookie(options =>
{
options.LoginPath = "/login";
options.LogoutPath = "/signout";
});
services.AddAuthentication().AddGoogle(socialProvider.ProviderName, o =>
{
o.ClientId = [REMOVED]
o.ClientSecret = [REMOVED]
o.UserInformationEndpoint = "https://www.googleapis.com/oauth2/v2/userinfo";
o.ClaimActions.Clear();
o.ClaimActions.MapJsonKey(ClaimTypes.NameIdentifier, "id");
o.ClaimActions.MapJsonKey(ClaimTypes.Name, "name");
o.ClaimActions.MapJsonKey(ClaimTypes.GivenName, "given_name");
o.ClaimActions.MapJsonKey(ClaimTypes.Surname, "family_name");
o.ClaimActions.MapJsonKey("urn:google:profile", "link");
o.ClaimActions.MapJsonKey(ClaimTypes.Email, "email");
o.CallbackPath = string.Format("/signin-{0}", socialProvider.ProviderName.ToLower());
o.SaveTokens = true;
o.Events.OnRemoteFailure = ctx =>
{
string message = UrlEncoder.Default.Encode(ctx.Failure.Message);
if (!string.IsNullOrEmpty(message) && message.Length > 1500)
{
message = message.Substring(0, 1499);
}
ctx.Response.Redirect(errorRedirectUrl + message);
ctx.HandleResponse();
return Task.FromResult(0);
};
});
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
Please also see the image below that shows the error when I have enabled "UseDeveloperExceptionPage".
FYI, I am completely unable to replicate the issue on my iPhone and my Desktop PC - I never receive the issue and I can make as many login attempts as I want, the issue never seems to arise on these devices.
I'm lost!
I was able to identify my issue here which turns out to be unique to any other answer I found with the same error I experienced above.
Issue: On my Pixel device, I have an application (My-App) that runs against the same domain that I was accessing in my Chrome browser. When clicking to login via Google, I remember it asked me if I wanted to 'Open in Chrome' or 'Open in My-App', and I always selected 'Open in Chrome'.
I uninstalled My-App, and now I am unable to replicate the issue. The issue is gone. I tried the scenario many times to no avail, every time it worked! When I re-installed My-App, the issue came back.
Fix: the problem that I need to resolve is running my Core project on a different domain other than the domain My-App is running, so there won't be a confusion on the device about whether Chrome should open or My-App should open. Hopefully that will be my fix!
Thanks for reading.

why is Graph API Update not working but other functions working

Hello i am getting an error when using Microsoft graph api, i am getting a 403 error when I am updating a planner task.
StatusCode:403,
ReasonPhrase:'Forbidden',
Version:1.1,
Content:System.Net.Http.StreamContent,
Headers:{
Transfer-Encoding: chunked request-id:7 c6e6c64-60e8-4d65-a248-c91841f8f8ca client-request-id:7 c6e6c64-60e8-4d65-a248-c91841f8f8ca x-ms-ags-diagnostic:{
"ServerInfo":{
"DataCenter":"North Europe",
"Slice":"SliceC",
"Ring":"3",
"ScaleUnit":"001",
"Host":"AGSFE_IN_70",
"ADSiteName":"NEU"
}
} Duration:184.823 Strict-Transport-Security: max-age=31536000 Cache-Control: private Date:Wed,
03 Oct 2018 06:24:41 GMT Content-Type:application/json
}
}
I have created my own plan to create tasks and assign them accordingly. This application used to work without any issue but suddenly it started throwing this issue.
This issue only occurs on the update, other functions like the read, create and delete work without any issue.
I have full office 365 admin rights, so it is not admin related issues. I have looked at the Graph Api on Git Hub to see possible causes of this problem. In the git hub it states if a particular code is shown it can be referenced to the cause of the problem but there is no code provided
Planner Api Documentation
Any help would be appreciated to solve this issue
This was solved through trial and error.
The problem with it was due to me trying to modify the PlanId which i found out cannot be modified on update.
Once the PlanId part was removed from the api post request it updated without any issue

Wordpress - Contact form 7 email not received

I am unable to receive email in my configured email in contact form 7 (in word press). All of the email finally end up in my default email account with the subject "Mail delivery failed: returning message to sender"
The body of the email is given as under. One thing i noticed is that the 'recepient' is test#test.com, while i configured the To to my own email id. The snapshot of my config is (I changed my own domain name with sample mydomain for security purposes):
The failure email i end up getting in the default email id is:
This message was created automatically by mail delivery software.
A message that you sent could not be delivered to one or more of its
recipients. This is a permanent error. The following address(es) failed:
test#test.com
host secureserver.net [85.45.125.0]
SMTP error from remote mail server after RCPT TO:<test#test.com>:
550 5.1.1 <test#test.com> recipient rejected. This is a default recipient used as a placeholder in many web applications. Please check your settings and try again.
------ This is a copy of the message, including all the headers. ------
Return-path: <myname#secureserver.net>
Received: from myname by secureserver.net with local (Exim 4.85)
(envelope-from <myname#secureserver.net>)
id 1Z9pj0-002GGR-NL
for test#test.com; Tue, 30 Jun 2015 00:12:58 -0700
To: test#test.com
Subject: [mydomain! Contact] From hi
X-PHP-Script: www.mydomain.com/index.php for 85.52.214.184
Date: Tue, 30 Jun 2015 07:12:58 +0000
From: hi <test#test.com>
Message-ID: <b325164dd89b7dbe9861fdf0e1f578c1###str_replacement_1##>
X-Priority: 3
X-Mailer: PHPMailer 5.2.7 (https://github.com/PHPMailer/PHPMailer/)
Reply-To: hi#gmail.com
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Name: hi
Email: hi#gmail.com
Comments: hi hihihi
Sending and receving emails with CF7 works very well for most people. Anyone who has problems should check server configurations and take a look at Contact Form 7 Email Issues.

How to solve error "connection:closed" in SharePoint2010?

Hi , when i deleted site under mysite collection the webapplication
doesnot work and i had this error
HTTP/1.1 200 OK Server: Microsoft-IIS/7.5 Date: Fri, 13 Dec 2013
07:03:54 GMT Connection: close
When I checked the log file I had this :
From Microsoft support page
Cause
This is caused by insufficient permissions for the search service account on the SharePoint Server. Verify that no group policies have been set on the local user groups 'WSS_WPG' and 'WSS_ADMIN_WPG'.
Resolution
Check the system event log for group policy changes that may have occurred around the same time as the search errors. Determine if any group policies have altered permissions on 'WSS_WPG', or WSS_ADMIN_WPG groups
From the folder %COMMONPROGRAMFILES%\Microsoft Shared\web server extensions\14\bin run the Psconfig command-line tool for SharePoint Products as follows:
Psconfig -cmd secureresources

Resources