Azure Mobile Services / VS Tools for Cordova - 404 - azure-mobile-services

I'm trying to get started with Azure Mobile Services and Visual Studio Tools for Apache Cordova. (https://msdn.microsoft.com/en-gb/magazine/dn879353.aspx)
I want to use the Mobile Service for push notifications. I've created the service, with a Node backend, and a TodoItem table. I've got a GCM set up too.
However, when trying to register a template, I get a 404 Not Found error:
var GCM_SENDER_ID = 'MY_GCM_ID';
mobileServiceClient = new WindowsAzure.MobileServiceClient(
"MY_URL",
"MY_API_KEY"
);
pushNotification = PushNotification.init({
"android": { "senderID": GCM_SENDER_ID }
});
pushNotification.on('registration', function (data) {
var handle = data.registrationId; //This appears to be set alright
var platform = device.platform; // This is 'Android'
if (platform == 'android' || platform == 'Android') {
var template = '{ "data" : {"message":"$(message)"}}';
mobileServiceClient.push.gcm.registerTemplate(handle, 'myTemplate', template, null);
});
The final line gives me a 404. I'm running the app in the Google Android Emulator.
EDIT: I tried calling the registrations endpoint using Postman: https://myservice.azure-mobile.net/push/registrations?platform=gcm&deviceId=
If I do a GET, I get [] as a response, if I do a POST, I get 404

Finally fixed it - I didn't have the Cordova Whitelist Plugin installed!
I realised after debugging into MobileServices.Web.js and seeing that the exact same request that was successful with Postman was failing in the Android Emulator.

Related

AWS CDK: Api Key ignored when testing api gateway locally?

I'm currently developping an API with aws-cdk and I'm testing it locally with aws-sam-cli and docker. I wanted to add the requirement of an API Key to call the API.
Here is the code inside my stack:
const api = new apigw.RestApi(this, "MyAPI", {
restApiName: "My API",
description: "BLABLABLA API",
});
const myLambdaIntegration = new apigw.LambdaIntegration(myLambda, {
proxy: false,
});
// Endpoints of the API
api.root.addResource("test").addMethod("GET", myLambdaIntegration, {
apiKeyRequired: true,
});
Then I build this stack and synth it (npm run build ; cdk synth --no-staging myStack > template.yaml
And try to test it locally
sam local start-api
When I request my api without any API KEY, the API returns me the result of my lambda. 😭
I expected it to return me an error like {"message":"Missing Authentication Token"}
Does anyone have an idea of what is going on?
I suspect it's because authorizations are ignored locally but didn't find anything about that...
Thanks in advance! 😁
Edit: After deploying this stack, the API correctly asks me for a token.

Http request working on ionic serve but doesn't work on "ionic cordova run android --device"

I am using Ionic native http to make server requests. The server is hosted on aws and the apis are up and running (verified by postman).
When i do ionic serve the requests go through and work but when i try to run it on device it doesnt work. On inspection i get "net::ERR_CLEARTEXT_NOT_PERMITTED" and post is sent as OPTIONS
ERROR HttpErrorResponse {headers: HttpHeaders, status: 0, statusText: "Unknown Error", url: "http://18.220.143.133/api/login", ok: false, …}
already tried adding to config.xml
login(user: User): Observable<AuthResponse> {
return this.httpClient.post('http://18.220.143.133/api/login', user, {
headers: new HttpHeaders().set('Content-Type', 'application/json'),
}).pipe(
tap(async (res: AuthResponse) => {
if (res.success == true) {
await this.storage.set('user',res.user);
await this.storage.set('ACCESS_TOKEN', res.token);
this.authSubject.next(true);
}
})
);
}
I expect http requests to go through from mobile devices as well.
The same happened to me, until in the config.xml file I added:
<preference name = "android-targetSdkVersion" value = "27" />
It has to do with your CORS for the API call. This may help. Also, since you're using Angular HTTP requests, check here HTTP request from angular will send with method OPTIONS instead of POST.

Cors request Rejected

I am facing an error and I don't known what to do. Whenever I try to save user to my ionic user service using the following code:
Ionic.io();
var user = Ionic.User.current();
if (user.id) {
user.set('name', username);
//user.set('image',image_name);
}
user.save();
and then I get this error:
Ionic User: Error: CORS request rejected
XMLHttpRequest cannot load https://api.ionic.io/auth/users/null.
Response for preflight has invalid HTTP status code 404
OPTIONS https:// api .ionic .io /auth /users /null
[cors request rejected][1]
[coding][2]
Ionic has a cordova plugin that sorts out all CORS issues called "cordova-plugin-whitelist". When you test through the browser, the Cordova plugins are not active, hence it's not sorting out your issues. Only when you deploy your app to android/ios/windows will the Cordova plugins work.
Rather get "Allow-Control-Allow-Origin" chrome plugin to allow you to make requests if you want to test on your browser.

LDAP authentication fails on ripple and actual device but not on browser

I'm trying to get an authorization token for an Ionic App from a LDAP service in a remote server.
I can get the auth token when I run the Ionic App in the browser with the command ionic serve and when I use Postman,
BUT it takes lot of time and eventually fails when I debug using ripple for the App or when I test on the phone or tablet.
The error says:
status: 503
statusText: Service Unavailable
data: html code from http://s3.amazonaws.com/heroku_pages/error.html
var deferred = $q.defer();
var req = {
method: 'GET',
url: 'http://host:port/adap?bind=token',
headers: {
Authorization: 'Basic <username>:<password>'
}
};
$http( req )
.then(function(data, status, headers, config) {
console.log(data);
deferred.resolve(data.data);
})
.catch(function(data) {
console.error(data.data);
deferred.reject(err);
});
return deferred.promise;
Does anybody have some hint about this issue?
Thanks in advance
For what you say the service is available, so the problem must be in the app side.
Check IP tables, and check ripple's proxy and set it to none.

How to solve Android GCM 401 Error?

Have setup a project at Google Code APis console and have a server key at "Key for server apps (with IP locking)". I'am trying to send a push notification to GCM device using "API key" and one registration ID that I have stored at database.
For server side I'am using Zend_Mobile_Push_Gcm and have something like this:
$token = 'REGISTRATION ID';
$apiKey = 'API KEY';
//Send test push
$message = new Zend_Mobile_Push_Message_Gcm();
$message->setId(time());
$message->addToken($token);
$message->setData(array('foo' => 'bar', 'bar'=>'foo'));
$gcm = new Zend_Mobile_Push_Gcm();
$gcm->setApiKey($apiKey);
try {
$response = $gcm->send($message);
} catch (Zend_Mobile_Push_Exception $e) {
die($e->getMessage());
}
On the app side, I have used the GCM demo, that is currently registering it's registration ID on a server service.
I'am not able to send the push, always get a 401 error. Have gone through troubleshooting and tried my API KEY and Registration ID with the CLI test line at http://developer.android.com/guide/google/gcm/gcm.html#auth_error but with no success.
Any help would be appreciated.
I realise this was posted a while ago but be sure to use your server API key and not your android API key.
I had the same issue when trying to use my Android API key from PHP with Zend.