Skip to content

Parse.User.logInWith calls api.parse.com #5130

@r03ert0

Description

@r03ert0

Issue Description

I have a parse server running in my localhost, and I am trying to login using Github. I use hellojs to get an access token. Based on information found on the web, I'm then trying to use Parse.User.logInWith, however, when I do it I get an error: my app is trying to connect to https://api.parse.com.

Steps to reproduce

Client code:

<html>
<body>
<script src="src/hello.polyfill.js"></script>
<script src="src/hello.js"></script>
<script src="src/modules/github.js"></script>
<script src="https://npmcdn.com/parse/dist/parse.min.js"></script>

<button onclick="hello('github').login()">Login with GitHub</button>
<div id='profile'></div>

<script>
const parseClientID = "[MY_PARSE_APP_ID]";
const githubClientID = "[MY_GITHUB_APP_ID]";
Parse.initialize(parseClientID);
var provider = {
  authenticate(options) {if (options.success) {options.success(this, {});}},
  restoreAuthentication(authData) {},
  getAuthType() {return 'github';},
  deauthenticate() {}
};
let authData = {authData: {auth_token: 'REPLACED_ON_THE_FLY', id: githubClientID}}
hello.init({github: githubClientID}, {
    oauth_proxy: 'http://localhost:3000/proxy',
    redirect_uri: 'http://localhost:3000/redirect'
});
hello.on('auth.login', (auth) => {
    authData.authData.auth_token = auth.authResponse.access_token;
    var user = new Parse.User();
    Parse.User.logInWith(provider, authData).then(usr=>console.log(usr), err=>console.log(err));
});
</script>
</body>
</html>

Server code:

var createError = require('http-errors');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var ParseServer = require('parse-server').ParseServer;
var oauthshim = require('oauth-shim');
var app = express();
app.get('/', (req, res) => {res.render('index');});
app.get('/redirect', (req, res) => {res.render('redirect');});
var api = new ParseServer({
    "appId": "[MY_PARSE_APP_ID]",
    "masterKey": "[MY_PARSE_MASTER_KEY]",
    "appName": "connect",
    "databaseURI": "mongodb://127.0.0.1:27017/parse",
    "serverURL": "http://localhost:1337/parse",
});
app.use('/parse', api);
oauthshim.init([{
    client_id: '[MY_GITHUB_APP_ID]',
    client_secret: '[MY_GITHUB_SECRET]',
    grant_url: 'https://github.com/login/oauth/access_token',
    domain: 'http://localhost:3000/redirect'
}]);
app.use('/proxy', oauthshim);
app.listen(1337, function() {console.log('parse-server running on port 1337.');});
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use(function(req, res, next) { next(createError(404));});
app.use(function(err, req, res, next) {
  res.locals.message = err.message;
  res.locals.error = req.app.get('env') === 'development' ? err : {};
  res.status(err.status || 500);
  res.render('error');
});
module.exports = app;

The client displays a single "login" button. On clicking, it connects to github, gets an access token, which is then used to Parse.User.logInWith(). This command fails, because of an attempt to connect to api.parse.com (probably some legacy code??)

Expected Results

I expected Parse.User.logInWith() to connect to my local server to login the user.

Actual Outcome

Parse attempts to connect to api.parse.com (which fails)

Environment Setup

  • Server

    • parse-server version (Be specific! Don't say 'latest'.) : Node: "parse-server": "^3.0.0", Client: Parse JavaScript SDK v2.1.0
    • Operating System: Mac OS X
    • Hardware: MacBook Pro 15"
    • Localhost or remote server? localhost
  • Database

    • MongoDB version: v3.4.17
    • Storage engine: default
    • Hardware: MacBookPro 15"
    • Localhost or remote server? (AWS, mLab, ObjectRocket, Digital Ocean, etc): localhost

Logs/Trace

In the Web Console:

Failed to load https://api.parse.com/1/users: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. The response had HTTP status code 410.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions