Skip to content

Any request with the Android SDK responds with "unauthorized" #635

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

Closed
ricamgar opened this issue Feb 24, 2016 · 8 comments
Closed

Any request with the Android SDK responds with "unauthorized" #635

ricamgar opened this issue Feb 24, 2016 · 8 comments

Comments

@ricamgar
Copy link

I am always getting "unauthorized" when I try to perform any operation with the Android SDK.

I followed the migration guide and deployed the parse-server to Heroku and MongoLab

The server seems to be up and running. Here the last logs:
screen shot 2016-02-24 at 23 10 15

I am using the last Android SDK library:
compile 'com.parse:parse-android:1.13.0'

and initialising Parse on the app with:

Parse.initialize(new Parse.Configuration.Builder(getApplicationContext())
        .applicationId("myAppId")
        .clientKey("myClientKey")
        .server("http://myApp.herokuapp.com/parse/")   // '/' important after 'parse'
        .build());

Thanks for your support!

@simonbengtsson
Copy link
Contributor

What is your parse server configuration? Also share the whole error messages including http status code. With the latest version of parse server unauthorized mainly happens when there are some problems or mismatch with the appId or keys. For example, currently it is important to not set any keys (part from the master key) in the parse configuration.

@ricamgar
Copy link
Author

With my configuration, do you mean the index.js file? If so, it is the following:

// Example express application adding the parse-server module to expose Parse
// compatible API routes.

var express = require('express');
var ParseServer = require('parse-server').ParseServer;

var databaseUri = process.env.DATABASE_URI || process.env.MONGOLAB_URI;

if (!databaseUri) {
  console.log('DATABASE_URI not specified, falling back to localhost.');
}

var api = new ParseServer({
  databaseURI: databaseUri || 'mongodb://localhost:27017/dev',
  cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
  appId: process.env.APP_ID || 'myAppId',
  masterKey: process.env.MASTER_KEY || '' //Add your master key here. Keep it secret!
});
// Client-keys like the javascript key or the .NET key are not necessary with parse-server
// If you wish you require them, you can set them as options in the initialization above:
// javascriptKey, restAPIKey, dotNetKey, clientKey

var app = express();

// Serve the Parse API on the /parse URL prefix
var mountPath = process.env.PARSE_MOUNT || '/parse';
app.use(mountPath, api);

// Parse Server plays nicely with the rest of your web routes
app.get('/', function(req, res) {
  res.status(200).send('I dream of being a web site.');
});

var port = process.env.PORT || 1337;
app.listen(port, function() {
    console.log('parse-server-example running on port ' + port + '.');
});

This is the log when I execute git push heroku master

remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Using set buildpack heroku/nodejs
remote: -----> Node.js app detected
remote: 
remote: -----> Creating runtime environment
remote:        
remote:        NPM_CONFIG_LOGLEVEL=error
remote:        NPM_CONFIG_PRODUCTION=true
remote:        NODE_ENV=production
remote:        NODE_MODULES_CACHE=true
remote: 
remote: -----> Installing binaries
remote:        engines.node (package.json):  >=4.3
remote:        engines.npm (package.json):   unspecified (use default)
remote:        
remote:        Resolving node version >=4.3 via semver.io...
remote:        Downloading and installing node 5.6.0...
remote:        Using default npm version: 3.6.0
remote: 
remote: -----> Restoring cache
remote:        Loading 2 from cacheDirectories (default):
remote:        - node_modules
remote:        - bower_components (not cached - skipping)
remote: 
remote: -----> Building dependencies
remote:        Pruning any extraneous modules
remote:        Installing node modules (package.json)
remote: 
remote: -----> Caching build
remote:        Clearing previous node cache
remote:        Saving 2 cacheDirectories (default):
remote:        - node_modules
remote:        - bower_components (nothing to cache)
remote: 
remote: -----> Build succeeded!
remote:        ├── [email protected]
remote:        ├── [email protected]
remote:        ├── [email protected]
remote:        └── [email protected]
remote:        
remote: 
remote: -----> Discovering process types
remote:        Procfile declares types     -> (none)
remote:        Default types for buildpack -> web
remote: 
remote: -----> Compressing...
remote:        Done: 17.5M
remote: -----> Launching...
remote:        Released v6
remote:        https://ancient-everglades-27765.herokuapp.com/ deployed to Heroku
remote: 
remote: Verifying deploy... done.

And this the log from the heroku logs command:

2016-02-25T13:26:42.211826+00:00 heroku[slug-compiler]: Slug compilation started
2016-02-25T13:26:42.211835+00:00 heroku[slug-compiler]: Slug compilation finished
2016-02-25T13:26:42.071598+00:00 heroku[api]: Deploy 78587fc by [email protected]
2016-02-25T13:26:42.071598+00:00 heroku[api]: Release v13 created by [email protected]
2016-02-25T13:31:20.557204+00:00 heroku[web.1]: Starting process with command `npm start`
2016-02-25T13:31:19.157073+00:00 heroku[web.1]: State changed from down to starting
2016-02-25T13:31:19.156767+00:00 heroku[web.1]: Unidling
2016-02-25T13:31:22.361066+00:00 app[web.1]: 
2016-02-25T13:31:22.361088+00:00 app[web.1]: > [email protected] start /app
2016-02-25T13:31:22.361090+00:00 app[web.1]: > node index.js
2016-02-25T13:31:22.361091+00:00 app[web.1]: 
2016-02-25T13:31:23.340693+00:00 app[web.1]: parse-server-example running on port 28248.
2016-02-25T13:31:23.732412+00:00 heroku[web.1]: State changed from starting to up
2016-02-25T13:31:24.218968+00:00 heroku[router]: at=info method=POST path="/parse/login" host=notificationreminder.herokuapp.com request_id=083c5434-60c3-4bec-b524-ddb08dcd4203 fwd="188.108.179.50" dyno=web.1 connect=1ms service=23ms status=403 bytes=273

And about the error messages, the only info I see is the ParseRequestException: unauthorized. Or do you mean another thing? Sorry, I very new on backend development...

Thanks!

@rogerhu
Copy link
Contributor

rogerhu commented Feb 25, 2016

Set clientKey to null...unless you've defined one in the Nose server you shouldn't supply one.

@ricamgar
Copy link
Author

@rogerhu do you mean the clientKey on the SDK initialisation? I tried that and I get the same error...

@rogerhu
Copy link
Contributor

rogerhu commented Feb 25, 2016

I ran into your same issue and I found out that it was that serverURL was not set on index.js. The latest parse-server-example now includes it so just to pull that config and redeploy and try again!

@simonbengtsson
Copy link
Contributor

The latest parse server update fails instead of giving the unauthorized error if serverurl is not set so unless you are running an old version that is probably not the issue. I saw that it reports a 403 status code, could you double check that the appid and master key is correctly set on both client and server?

@ricamgar
Copy link
Author

It works!! As @simonbengtsson said, the problem was that I was using the old applicationId from Parse.com. When changing to the APP_ID from Heroku it worked perfectly!
Thanks @rogerhu and @simonbengtsson!

@simonbengtsson
Copy link
Contributor

Glad it was an easy fix!

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

No branches or pull requests

3 participants