Skip to content

Commit

Permalink
pm2 login/register: fix legacy login
Browse files Browse the repository at this point in the history
  • Loading branch information
Unitech committed May 29, 2018
1 parent f024968 commit 99cd385
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions lib/API/Keymetrics/kmapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -24,27 +25,27 @@ 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
}, function(err, res) {
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,
Expand Down

0 comments on commit 99cd385

Please sign in to comment.