pm2 login/register: fix legacy login

This commit is contained in:
Alexandre Strzelewicz 2018-05-29 21:36:34 +02:00
parent f0249684bc
commit 99cd385038

View File

@ -5,6 +5,7 @@ var url = require('url');
var cst = require('../../../constants.js');
var KM = function() {
this.AUTH_URI = 'https://id.keymetrics.io';
this.BASE_URI = 'https://app.keymetrics.io';
this.CLIENT_ID = '938758711';
this.CB_URI = 'https://app.keymetrics.io';
@ -24,19 +25,19 @@ KM.prototype.loginAndGetAccessToken = function (user_info, cb) {
var URL_AUTH = '/api/oauth/authorize?response_type=token&scope=all&client_id=' +
that.CLIENT_ID + '&redirect_uri=' + that.CB_URI;
needle.get(that.BASE_URI + URL_AUTH, function(err, res) {
needle.get(that.AUTH_URI + URL_AUTH, function(err, res) {
if (err) return cb(err);
var cookie = res.cookies;
needle.post(that.BASE_URI + '/api/oauth/login', user_info, {
needle.post(that.AUTH_URI + '/api/oauth/login', user_info, {
cookies : cookie
}, function(err, resp, body) {
if (err) return cb(err);
if (body.indexOf('/api/oauth/login') > -1) return cb('Wrong credentials');
if (resp.statusCode != 200) return cb('Wrong credentials');
var location = resp.headers.location;
var redirect = that.BASE_URI + location;
var location = resp.headers['x-redirect'];
var redirect = that.AUTH_URI + location;
needle.get(redirect, {
cookies : cookie
@ -44,7 +45,7 @@ KM.prototype.loginAndGetAccessToken = function (user_info, cb) {
if (err) return cb(err);
var refresh_token = querystring.parse(url.parse(res.headers.location).query).access_token;
needle.post(that.BASE_URI + '/api/oauth/token', {
needle.post(that.AUTH_URI + '/api/oauth/token', {
client_id : that.CLIENT_ID,
grant_type : 'refresh_token',
refresh_token : refresh_token,