Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 93 additions & 4 deletions dist/ng-cordova-oauth.js
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,8 @@
'oauth.xing',
'oauth.netatmo',
'oauth.trakttv',
'oauth.yahoo'])
'oauth.yahoo',
'oauth.ttam'])
.factory("$cordovaOauth", cordovaOauth);

function cordovaOauth(
Expand All @@ -1047,7 +1048,7 @@
$ngCordovaTwitter, $ngCordovaMeetup, $ngCordovaSalesforce, $ngCordovaStrava, $ngCordovaWithings, $ngCordovaFoursquare, $ngCordovaMagento,
$ngCordovaVkontakte, $ngCordovaOdnoklassniki, $ngCordovaImgur, $ngCordovaSpotify, $ngCordovaUber, $ngCordovaWindowslive, $ngCordovaYammer,
$ngCordovaVenmo, $ngCordovaStripe, $ngCordovaRally, $ngCordovaFamilySearch, $ngCordovaEnvato, $ngCordovaWeibo, $ngCordovaJawbone, $ngCordovaUntappd,
$ngCordovaDribble, $ngCordovaPocket, $ngCordovaMercadolibre, $ngCordovaXing, $ngCordovaNetatmo, $ngCordovaTraktTv, $ngCordovaYahoo) {
$ngCordovaDribble, $ngCordovaPocket, $ngCordovaMercadolibre, $ngCordovaXing, $ngCordovaNetatmo, $ngCordovaTraktTv, $ngCordovaYahoo, $ngCordovaTtam) {

return {
azureAD: $ngCordovaAzureAD.signin,
Expand Down Expand Up @@ -1090,7 +1091,8 @@
xing: $ngCordovaXing.signin,
netatmo: $ngCordovaNetatmo.signin,
trakttv: $ngCordovaTraktTv.signin,
yahoo: $ngCordovaYahoo.signin
yahoo: $ngCordovaYahoo.signin,
ttam: $ngCordovaTtam.signin,
};
}

Expand Down Expand Up @@ -1136,7 +1138,8 @@
'$ngCordovaXing',
'$ngCordovaNetatmo',
'$ngCordovaTraktTv',
'$ngCordovaYahoo'
'$ngCordovaYahoo',
'$ngCordovaTtam'
];
})();

Expand Down Expand Up @@ -2233,6 +2236,92 @@
trakttv.$inject = ['$q', '$http', '$cordovaOauthUtility'];
})();

(function() {
'use strict';

angular.module('oauth.ttam', ['oauth.utils'])
.factory('$ngCordovaTtam', ttam);

function ttam($q, $http, $cordovaOauthUtility) {
return {
signin: oauthTtam,
};

/*
* Sign into the Ttam service
*
* @param string clientId
* @param array appScope
* @param object options
* @return promise
*/
function oauthTtam(clientId, clientSecret,appScope, options) {
var deferred = $q.defer();
if(window.cordova) {
if($cordovaOauthUtility.isInAppBrowserInstalled()) {
var redirect_uri = "http://localhost/callback";
if(options !== undefined) {
if(options.hasOwnProperty("redirect_uri")) {
redirect_uri = options.redirect_uri;
}
}
var flowUrl = "https:/api.23andme.com/authorize/?client_id=" + clientId + "&redirect_uri=" + redirect_uri + "&response_type=code&scope=" + appScope;
if(options !== undefined && options.hasOwnProperty("auth_type")) {
flowUrl += "&auth_type=" + options.auth_type;
}

var browserRef;
browserRef = window.cordova.InAppBrowser.open(flowUrl, '_blank', 'location=no');

browserRef.addEventListener('loadstart', function(event) {
if((event.url).indexOf(redirect_uri) === 0) {
try {
var requestToken = (event.url).split("code=")[1].split("&")[0];
$http({
method: "post",
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
url: "https://api.23andme.com/token",
data:
"client_id=" + clientId +
"&client_secret=" + clientSecret +
"&redirect_uri=" + redirect_uri +
"&grant_type=authorization_code" +
"&code=" + requestToken +
"&scope="+appScope})
.success(function(data) {
deferred.resolve(data);
})
.error(function(data, status) {
deferred.reject("Problem authenticating: "+data.error_description);
})
.finally(function() {
setTimeout(function() {
browserRef.close();
}, 10);
});
}catch(e){
setTimeout(function() {
browserRef.close();
}, 10);
}
}
});
browserRef.addEventListener('exit', function(event) {
deferred.reject("The sign in flow was canceled");
});
} else {
deferred.reject("Could not find InAppBrowser plugin");
}
} else {
deferred.reject("Cannot authenticate via a web browser");
}
return deferred.promise;
}
}

ttam.$inject = ['$q', '$http', '$cordovaOauthUtility'];
})();

(function() {
'use strict';

Expand Down
6 changes: 3 additions & 3 deletions dist/ng-cordova-oauth.min.js

Large diffs are not rendered by default.

11 changes: 7 additions & 4 deletions src/oauth.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
'oauth.xing',
'oauth.netatmo',
'oauth.trakttv',
'oauth.yahoo'])
'oauth.yahoo',
'oauth.ttam'])
.factory("$cordovaOauth", cordovaOauth);

function cordovaOauth(
Expand All @@ -53,7 +54,7 @@
$ngCordovaTwitter, $ngCordovaMeetup, $ngCordovaSalesforce, $ngCordovaStrava, $ngCordovaWithings, $ngCordovaFoursquare, $ngCordovaMagento,
$ngCordovaVkontakte, $ngCordovaOdnoklassniki, $ngCordovaImgur, $ngCordovaSpotify, $ngCordovaUber, $ngCordovaWindowslive, $ngCordovaYammer,
$ngCordovaVenmo, $ngCordovaStripe, $ngCordovaRally, $ngCordovaFamilySearch, $ngCordovaEnvato, $ngCordovaWeibo, $ngCordovaJawbone, $ngCordovaUntappd,
$ngCordovaDribble, $ngCordovaPocket, $ngCordovaMercadolibre, $ngCordovaXing, $ngCordovaNetatmo, $ngCordovaTraktTv, $ngCordovaYahoo) {
$ngCordovaDribble, $ngCordovaPocket, $ngCordovaMercadolibre, $ngCordovaXing, $ngCordovaNetatmo, $ngCordovaTraktTv, $ngCordovaYahoo, $ngCordovaTtam) {

return {
azureAD: $ngCordovaAzureAD.signin,
Expand Down Expand Up @@ -96,7 +97,8 @@
xing: $ngCordovaXing.signin,
netatmo: $ngCordovaNetatmo.signin,
trakttv: $ngCordovaTraktTv.signin,
yahoo: $ngCordovaYahoo.signin
yahoo: $ngCordovaYahoo.signin,
ttam: $ngCordovaTtam.signin,
};
}

Expand Down Expand Up @@ -142,6 +144,7 @@
'$ngCordovaXing',
'$ngCordovaNetatmo',
'$ngCordovaTraktTv',
'$ngCordovaYahoo'
'$ngCordovaYahoo',
'$ngCordovaTtam'
];
})();
85 changes: 85 additions & 0 deletions src/oauth.ttam.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
(function() {
'use strict';

angular.module('oauth.ttam', ['oauth.utils'])
.factory('$ngCordovaTtam', ttam);

function ttam($q, $http, $cordovaOauthUtility) {
return {
signin: oauthTtam,
};

/*
* Sign into the Ttam service
*
* @param string clientId
* @param array appScope
* @param object options
* @return promise
*/
function oauthTtam(clientId, clientSecret,appScope, options) {
var deferred = $q.defer();
if(window.cordova) {
if($cordovaOauthUtility.isInAppBrowserInstalled()) {
var redirect_uri = "http://localhost/callback";
if(options !== undefined) {
if(options.hasOwnProperty("redirect_uri")) {
redirect_uri = options.redirect_uri;
}
}
var flowUrl = "https:/api.23andme.com/authorize/?client_id=" + clientId + "&redirect_uri=" + redirect_uri + "&response_type=code&scope=" + appScope;
if(options !== undefined && options.hasOwnProperty("auth_type")) {
flowUrl += "&auth_type=" + options.auth_type;
}

var browserRef;
browserRef = window.cordova.InAppBrowser.open(flowUrl, '_blank', 'location=no');

browserRef.addEventListener('loadstart', function(event) {
if((event.url).indexOf(redirect_uri) === 0) {
try {
var requestToken = (event.url).split("code=")[1].split("&")[0];
$http({
method: "post",
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
url: "https://api.23andme.com/token",
data:
"client_id=" + clientId +
"&client_secret=" + clientSecret +
"&redirect_uri=" + redirect_uri +
"&grant_type=authorization_code" +
"&code=" + requestToken +
"&scope="+appScope})
.success(function(data) {
deferred.resolve(data);
})
.error(function(data, status) {
deferred.reject("Problem authenticating: "+data.error_description);
})
.finally(function() {
setTimeout(function() {
browserRef.close();
}, 10);
});
}catch(e){
setTimeout(function() {
browserRef.close();
}, 10);
}
}
});
browserRef.addEventListener('exit', function(event) {
deferred.reject("The sign in flow was canceled");
});
} else {
deferred.reject("Could not find InAppBrowser plugin");
}
} else {
deferred.reject("Cannot authenticate via a web browser");
}
return deferred.promise;
}
}

ttam.$inject = ['$q', '$http', '$cordovaOauthUtility'];
})();