Receive validationToken but Subscription validation request timed out - microsoft-graph-api

Anyone can help me?.
I want register subscription for user, i use ngrok.
I try use postman it success but in my web it error.
this is my log
[2020-07-20 11:12:52] local.INFO: Error: Client error: `POST https://graph.microsoft.com/v1.0/subscriptions` resulted in a `400 Bad Request` response:
{
"error": {
"code": "InvalidRequest",
"message": "Subscription validation request timed out.",
"inner (truncated...)
this is my validationToken i receive:
array (
'validationToken' => 'Validation: Testing client application reachability for subscription Request-Id: d11e795b-9b06-46ff-b2ba-0df49a6e1c5c',
)
and my code
try {
$graph = new Graph();
$graph->setAccessToken($this->token);
$sub = new Model\Subscription();
$sub->setChangeType("created");
$sub->setNotificationUrl($this->domain. '/api/receive-notification');
$sub->setResource( "users/" . $outlook_id . "/events");
$sub->setClientState('SecretClientState');
$dateTime = new Carbon();
$dateTime->addDays(3);
$sub->setExpirationDateTime($dateTime);
$subResult = $graph->createRequest("POST", "/subscriptions")
->attachBody($sub)
->setReturnType(Model\Subscription::class)
->execute();
dd($subResult);
} catch (\Exception $e) {
dd($e->getMessage());
}

Graph API only allows 4230 minutes into the future.
Change
$dateTime->addDays(3);
to
$dateTime->modify('+4230 minutes');

Related

NestJs HttpException response to Dart's http request

I would like to parse the response that my NestJs backend is sending to my Dart front end.
If from NestJs controller I reply with
return new HttpException('Already running..', HttpStatus.PROCESSING);
I receive on Dart's Response object:
Response: {
...
statusCode: 201
body {
"response": "Already running..",
"status":102,
"message": "Already running..",
"name": "HttpException"
}
}
Whereas if I return
throw new HttpExcpetion('Already running..', HttpStatus.PROCESSING)
I receive:
Response: {
...
statusCode: 102
body: ""
}
I would have expected to receive something like the below:
Response: {
...
statusCode: 102
message: "Already running..",
}
Any ideas how the two approaches are different and what should be the proper, consistent way so I know how to parse responses from backend?

Sms cannot be Sent via twilio getting 400 error

I am trying to send SMS via Twilio using HttpEntity from my Java code. I am getting 400 Bad Request with no details. The response is below.
[<html>
<head><title>400 Bad Request</title></head>
<body>
<center><h1>400 Bad Request</h1></center>
<hr><center>openresty</center>
</body>
</html>]
Below is the code I have used to send a request. The request is successful from Postman. I cannot use Java SDK and has to use RestTemplate.
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
headers.add("route-to-back-end-endpoint", "https://api.twilio.com/2010-04-01/Accounts/xxx/Messages.json");
MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
map.add("To", "+91*******");
map.add("From", "+1******");
map.add("Body", "Try try try");
HttpEntity<MultiValueMap<String, String>> entity = new HttpEntity<>(map, headers);
String response = null;
try {
restTemplateSsl.getInterceptors().add(new BasicAuthenticationInterceptor("xxx", "yyy"));
response = restTemplateSsl.postForObject("Internal Xml Gateway Link", entity, String.class);
} catch (Exception e) {
e.printStackTrace();
log.error("Exception : {} ", e.getMessage());
}
log.info("Response Received :{}", response);
return response;
The authentication is successful with Twilio. So no authentication issue. I am not sure what is exactly wrong in request.
You might get this error if the path in your HTTP request doesn't start with '/'.

Get 404 "The resource could not be found" when call /beta/informationprotection/policy/labels

according to documentation we may use the following endpoints for fetching sensitivity labels:
/me/informationProtection/policy/labels (using delegated permissions)
/informationProtection/policy/labels (using application permission. App should have InformationProtectionPolicy.Read.All permission to use this end point)
The following C# code uses app permissions and it works on tenant1:
static void Main(string[] args)
{
string accessToken = getTokenImpl().Result;
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
client.DefaultRequestHeaders.Add("Accept", "application/json");
client.DefaultRequestHeaders.Add("User-Agent", "PostmanRuntime/7.24.1");
using (var response = client.GetAsync($"https://graph.microsoft.com/beta/informationprotection/policy/labels").Result)
{
using (var content = response.Content)
{
string result = content.ReadAsStringAsync().Result;
if (response.IsSuccessStatusCode)
{
Console.WriteLine(result);
}
}
}
}
}
private static async Task<string> getTokenImpl()
{
string clientId = "...";
string clientSecret = "...";
string tenant = "{...}.onmicrosoft.com";
string authority = string.Format("https://login.microsoftonline.com/{0}", tenant);
var authContext = new AuthenticationContext(authority);
var creds = new ClientCredential(clientId, clientSecret);
var authResult = await authContext.AcquireTokenAsync("https://graph.microsoft.com/", creds);
return authResult.AccessToken;
}
But it doesn't work on another tenant2 - there it always returns 404 "The resource could not be found" with the following inner exception "User not found to have labels, policy is empty". Here is full response:
{
"error": {
"code": "itemNotFound",
"message": "The resource could not be found.",
"innerError": {
"code": "notFound",
"message": "User not found to have labels, policy is empty",
"target": "userId",
"exception": null,
"date": "2020-11-18T09:29:20",
"request-id": "657ad51c-9cab-49f2-a242-50929cdc6950",
"client-request-id": "657ad51c-9cab-49f2-a242-50929cdc6950"
}
}
}
Interesting that attempt to call endpoint /me/informationProtection/policy/labels with delegated permissions on the same tenant2 gives the same error, but on tenant1 it also works. Did anybody face with this problem or have idea why it may happen? Need to mention that on tenant2 earlier we created and published several sensitivity labels for specific user - this user doesn't have neither O365 license nor Azure subscription. I.e. when you try to login to SPO/Azure and create site/group - sensitivity labels were not shown at all for this user. We tried to remove these sensitivity labels and their policies with audience targeting to this user, but both end points still return error.
PS. AAD app is Ok on tenant2 - it has InformationProtectionPolicy.Read.All permission and admin consent is granted:
Update 2020-11-25: behavior has been changed on both tenants without any change from our side: now on both tenants we get 502 Bad Gateway. Does MS rolls out this functionality globally now? Here is response which we get now from /beta/me/informationProtection/policy/labels:
{
"error":{
"code":"UnknownError",
"message":"<html>\r\n<head><title>502 Bad Gateway</title></head>\r\n<body>\r\n<center><h1>502 Bad Gateway</h1></center>\r\n<hr><center>Microsoft-Azure-Application-Gateway/v2</center>\r\n</body>\r\n</html>\r\n",
"innerError":{
"date":"2020-11-25T12:59:51",
"request-id":"93557ae1-b0d9-44a9-bbea-871f18e379ea",
"client-request-id":"93557ae1-b0d9-44a9-bbea-871f18e379ea"
}
}
}
Update 2020-12-07: it started to work by its own. I.e. MS has fixed that on backend side somehow for the tenant when this issue was reproduced.

How to handle cloudboost errors in Ionic2?

The error I get when the user fails to log in is "Error: Request failed with status code 401". This error is logged here:
static login(username : string, password : string){
return new Promise(resolve =>{
let user = new CB.CloudUser();
user.set('username', username);
user.set('password', password);
user.logIn({
success: function(user) {
console.log("user");
resolve();
},
error: function(error) {
console.log(error);
resolve(error);
}
});
});
}
But what I need is the error that actually says what went wrong e.g. "invalid username" or "User is not authenticated".
How do I get these?
Error: Request failed with status code 401
This error generally means that the login request you made to the server was not authenticated/ you were not authorized to make the login request. This can mean that the CB instance is not properly initialized. Please check the appId and the master/client key you are using to initialize the CB instance.

Google play API returns error

i am getting the same issue as described in this post
. we have used almost exactly the same code. i have tried both with Client ID and Email address of the google service account in below mehotd
setServiceAccountId(GOOGLE_SERVICE_CLIENT_EMAIL) OR
setServiceAccountId(GOOGLE_CLIENT_ID)
error changes with the change in a/c id. if i use client id, error is
400 Bad Request { "error" : "invalid_grant" }
and if i use service email id, error is
401 Unauthorized {
"code" : 401, "errors" : [ {
"domain" : "androidpublisher",
"message" : "This developer account does not own the application.",
"reason" : "developerDoesNotOwnApplication" } ], "message" : "This developer account does not own the application." }
any idea?
There appears to be some evidence that Google Play API does not currently work with Service Accounts (madness). There is another thread on the issue here. You can read about the Google Service Accounts here. You can read about authentication for Android Google Play API here.
Once you have done the dance on the Google API Console to get a refresh_token you can get an access token like this:
private String getAccessToken()
{
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("https://accounts.google.com/o/oauth2/token");
try
{
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(4);
nameValuePairs.add(new BasicNameValuePair("grant_type", "refresh_token"));
nameValuePairs.add(new BasicNameValuePair("client_id", "YOUR_CLIENT_ID);
nameValuePairs.add(new BasicNameValuePair("client_secret", "YOUR_CLIENT_SECRET"));
nameValuePairs.add(new BasicNameValuePair("refresh_token", "YOUR_REFRESH_TOKEN"));
post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = client.execute(post);
BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
StringBuffer buffer = new StringBuffer();
for (String line = reader.readLine(); line != null; line = reader.readLine())
{
buffer.append(line);
}
JSONObject json = new JSONObject(buffer.toString());
return json.getString("access_token");
}
catch (IOException e) { e.printStackTrace(); }
catch (JSONException e) { e.printStackTrace(); }
return null;
}

Resources