Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
171 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
(function() { | ||
'use strict'; | ||
|
||
angular.module('oauth.trakttv', ['oauth.utils']) | ||
.factory('$ngCordovaTraktTv', trakttv); | ||
|
||
function trakttv($q, $http, $cordovaOauthUtility) { | ||
return { signin: oauthTraktTv }; | ||
|
||
/* | ||
* Sign into the Trakt.tv service | ||
* | ||
* @param string clientId | ||
* @param string clientSecret | ||
* @param string state | ||
* @param object options | ||
* @return promise | ||
*/ | ||
function oauthTraktTv(clientId, clientSecret, appScope, state, 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 browserRef = window.cordova.InAppBrowser.open('https://api-v2launch.trakt.tv/oauth/authorize?client_id=' + clientId + '&redirect_uri=' + redirect_uri + '&response_type=code&state=' + state, '_blank', 'location=no,clearsessioncache=yes,clearcache=yes'); | ||
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-v2launch.trakt.tv/oauth/token", data: "client_id=" + clientId + "&client_secret=" + clientSecret + "&redirect_uri=" + redirect_uri + "&grant_type=authorization_code" + "&code=" + requestToken }) | ||
.success(function(data) { | ||
deferred.resolve(data); | ||
}) | ||
.error(function(data, status) { | ||
deferred.reject("Problem authenticating"); | ||
}) | ||
.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; | ||
} | ||
} | ||
|
||
trakttv.$inject = ['$q', '$http', '$cordovaOauthUtility']; | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,7 @@ | |
* Jawbone | ||
* Untappd | ||
* Trakt.tv | ||
*/ | ||
|
||
angular.module("ngCordovaOauth", [ | ||
|