Fixes oath code url for livenet/testnet

This commit is contained in:
Gustavo Maximiliano Cortez 2015-09-07 19:45:03 -03:00
parent 71471f2aad
commit e9b74fcddc
No known key found for this signature in database
GPG Key ID: 15EDAD8D9F2EB1AF
4 changed files with 32 additions and 30 deletions

View File

@ -26,14 +26,15 @@
<img src="img/glidera-logo.png">
</div>
<div ng-if="!index.glideraToken && !index.glideraLoading && !index.glideraError" class="row">
<div ng-if="index.glideraCredentials && !index.glideraToken && !index.glideraLoading && !index.glideraError"
class="row">
<div class="columns" ng-init="showOauthForm = false">
<div class="text-center" ng-show="!showOauthForm">
<p translate>You can buy and sell Bitcoin with a US bank account directly in Copay.</p>
<div class="m10b text-gray size-12" translate>Connect your Glidera account to get started</div>
<button
<button
class="dark-gray outline round tiny"
ng-click="$root.openExternalLink(glidera.authenticateUrl); showOauthForm = true" translate>
ng-click="$root.openExternalLink(glidera.getAuthenticateUrl()); showOauthForm = true" translate>
Connect to Glidera
</button>
<div>

View File

@ -4,14 +4,17 @@ angular.module('copayApp.controllers').controller('glideraController',
function($scope, $timeout, $modal, applicationService, profileService, configService, storageService, glideraService) {
var config = configService.getSync().wallet.settings;
this.authenticateUrl = glideraService.getOauthCodeUrl();
this.submitOauthCode = function(code) {
this.getAuthenticateUrl = function() {
return glideraService.getOauthCodeUrl();
};
this.submitOauthCode = function(code, glideraCredentials) {
var fc = profileService.focusedClient;
var self = this;
this.loading = true;
$timeout(function() {
glideraService.getToken(code, function(error, data) {
glideraService.getToken(code, glideraCredentials, function(error, data) {
if (data && data.access_token) {
storageService.setGlideraToken(fc.credentials.network, data.access_token, function() {
$scope.$emit('Local/GlideraTokenUpdated', data.access_token);

View File

@ -113,6 +113,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.pendingTxProposalsCountForUs = null;
self.setSpendUnconfirmed();
self.glideraCredentials = null;
self.glideraToken = null;
self.glideraError = null;
self.glideraPermissions = null;
@ -839,6 +840,7 @@ console.log('[index.js:395]',txps); //TODO
self.initGlidera = function(accessToken) {
if (self.isShared) return;
self.glideraCredentials = glideraService.init(self.network);
var getToken = function(cb) {
if (accessToken) {
@ -852,7 +854,6 @@ console.log('[index.js:395]',txps); //TODO
if (err || !accessToken) return;
else {
self.glideraLoading = gettext('Connecting to Glidera...');
glideraService.init(self.network);
glideraService.getAccessTokenPermissions(accessToken, function(err, p) {
self.glideraLoading = null;
if (err) {

View File

@ -2,39 +2,36 @@
angular.module('copayApp.services').factory('glideraService', function($http, $log) {
var root = {};
var HOST;
var REDIRECT_URI;
var CLIENT_ID;
var CLIENT_SECRET;
var credentials = {};
root.init = function(network) {
if (network == 'testnet') {
HOST = 'https://sandbox.glidera.io';
REDIRECT_URI = 'urn:ietf:wg:oauth:2.0:oob';
CLIENT_ID = '9915b6ffa6dc3baffb87135ed3873d49';
CLIENT_SECRET = 'd74eda05b9c6a228fd5c85cfbd0eb7eb';
credentials.HOST = 'https://sandbox.glidera.io';
credentials.REDIRECT_URI = 'urn:ietf:wg:oauth:2.0:oob';
credentials.CLIENT_ID = '9915b6ffa6dc3baffb87135ed3873d49';
credentials.CLIENT_SECRET = 'd74eda05b9c6a228fd5c85cfbd0eb7eb';
}
else {
HOST = 'https://glidera.io';
REDIRECT_URI = 'urn:ietf:wg:oauth:2.0:oob';
CLIENT_ID = '';
CLIENT_SECRET = '';
}
credentials.HOST = 'https://glidera.io';
credentials.REDIRECT_URI = 'urn:ietf:wg:oauth:2.0:oob';
credentials.CLIENT_ID = '';
credentials.CLIENT_SECRET = '';
};
return credentials;
};
root.getOauthCodeUrl = function() {
return HOST
return credentials.HOST
+ '/oauth2/auth?response_type=code&client_id='
+ CLIENT_ID
+ credentials.CLIENT_ID
+ '&redirect_uri='
+ REDIRECT_URI;
+ credentials.REDIRECT_URI;
};
root.getToken = function(code, cb) {
var req = {
method: 'POST',
url: HOST + '/api/v1/oauth/token',
url: credentials.HOST + '/api/v1/oauth/token',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
@ -42,9 +39,9 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l
data: {
grant_type : 'authorization_code',
code: code,
client_id : CLIENT_ID,
client_secret: CLIENT_SECRET,
redirect_uri: REDIRECT_URI
client_id : credentials.CLIENT_ID,
client_secret: credentials.CLIENT_SECRET,
redirect_uri: credentials.REDIRECT_URI
}
};
@ -60,7 +57,7 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l
var _get = function(endpoint, token) {
return {
method: 'GET',
url: HOST + '/api/v1' + endpoint,
url: credentials.HOST + '/api/v1' + endpoint,
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
@ -172,7 +169,7 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l
var _post = function(endpoint, token, twoFaCode, data) {
return {
method: 'POST',
url: HOST + '/api/v1' + endpoint,
url: credentials.HOST + '/api/v1' + endpoint,
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',