Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added auth through Laravel Passport auth server #335

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Renamed provider from 'passport' to 'laravelPassport'
KyleMassacre committed Sep 15, 2017
commit 2d63a1d217acdf3ba99845b7607aeb137db2ee16
148 changes: 74 additions & 74 deletions dist/ng-cordova-oauth.js
Original file line number Diff line number Diff line change
@@ -1039,7 +1039,7 @@
'oauth.netatmo',
'oauth.trakttv',
'oauth.yahoo',
'oauth.passport'])
'oauth.laravelPassport'])
.factory("$cordovaOauth", cordovaOauth);

function cordovaOauth(
@@ -1048,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, $ngCordovaPassport) {
$ngCordovaDribble, $ngCordovaPocket, $ngCordovaMercadolibre, $ngCordovaXing, $ngCordovaNetatmo, $ngCordovaTraktTv, $ngCordovaYahoo, $ngCordovaLaravelPassport) {

return {
azureAD: $ngCordovaAzureAD.signin,
@@ -1092,7 +1092,7 @@
netatmo: $ngCordovaNetatmo.signin,
trakttv: $ngCordovaTraktTv.signin,
yahoo: $ngCordovaYahoo.signin,
passport: $ngCordovaPassport
passport: $ngCordovaLaravelPassport
};
}

@@ -1139,10 +1139,80 @@
'$ngCordovaNetatmo',
'$ngCordovaTraktTv',
'$ngCordovaYahoo',
'$ngCordovaPassport'
'$ngCordovaLaravelPassport'
];
})();

(function() {
'use strict';

angular.module('oauth.laravelPassport', ['oauth.utils'])
.factory('$ngCordovaLaravelPassport', laravelPassport);

function laravelPassport($q, $http, $cordovaOauthUtility) {
return { signin: oauthLaravelPassport };

/*
* Sign into the Laravel Passport service
*
* @param string clientId
* @param array appScope
* @param object options
* @return promise
*/
function oauthLaravelPassport(clientId, appScope, options) {
var deferred = $q.defer();
if(window.cordova) {
if($cordovaOauthUtility.isInAppBrowserInstalled()) {
var redirect_uri = "http://localhost/callback";
var target_url = '';
var client_secret = '';
if(options !== undefined) {
if(options.hasOwnProperty("redirect_uri")) {
redirect_uri = options.redirect_uri;
}
if(options.hasOwnProperty("target_url")) {
target_url = options.target_url;
}
if(options.hasOwnProperty('client_secret')) {
client_secret = options.client_secret;
}
}

var browserRef = window.cordova.InAppBrowser.open(target_url + '/oauth/authorize?response_type=code&client_id=' + clientId + '&redirect_uri='+ redirect_uri +'&scope=' + appScope.join(' '), '_blank', 'location=no,clearsessioncache=yes,clearcache=yes');
browserRef.addEventListener("loadstart", function(event) {
if((event.url).indexOf(redirect_uri) === 0) {
var requestToken = (event.url).split("code=")[1];

$http({method: "post", headers: {'Content-Type': 'application/x-www-form-urlencoded'}, url: target_url+ '/oauth/token', data: "client_id=" + clientId + "&client_secret=" + client_secret + "&redirect_uri=" + redirect_uri + "&grant_type=authorization_code" + "&code=" + requestToken })
.then(function(data) {
deferred.resolve(data);
})
.catch(function(data, status) {
deferred.reject(data);
})
.finally(function() {
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;
}
}
laravelPassport.$inject = ['$q', '$http', '$cordovaOauthUtility'];
})();

(function() {
'use strict';

@@ -1609,76 +1679,6 @@
odnoklassniki.$inject = ['$q', '$http', '$cordovaOauthUtility'];
})();

(function() {
'use strict';

angular.module('oauth.passport', ['oauth.utils'])
.factory('$ngCordovaPassport', passport);

function passport($q, $http, $cordovaOauthUtility) {
return { signin: oauthPassport };

/*
* Sign into the Laravel Passport service
*
* @param string clientId
* @param array appScope
* @param object options
* @return promise
*/
function oauthPassport(clientId, appScope, options) {
var deferred = $q.defer();
if(window.cordova) {
if($cordovaOauthUtility.isInAppBrowserInstalled()) {
var redirect_uri = "http://localhost/callback";
var target_url = '';
var client_secret = '';
if(options !== undefined) {
if(options.hasOwnProperty("redirect_uri")) {
redirect_uri = options.redirect_uri;
}
if(options.hasOwnProperty("target_url")) {
target_url = options.target_url;
}
if(options.hasOwnProperty('client_secret')) {
client_secret = options.client_secret;
}
}

var browserRef = window.cordova.InAppBrowser.open(target_url + '/oauth/authorize?response_type=code&client_id=' + clientId + '&redirect_uri='+ redirect_uri +'&scope=' + appScope.join(' '), '_blank', 'location=no,clearsessioncache=yes,clearcache=yes');
browserRef.addEventListener("loadstart", function(event) {
if((event.url).indexOf(redirect_uri) === 0) {
var requestToken = (event.url).split("code=")[1];

$http({method: "post", headers: {'Content-Type': 'application/x-www-form-urlencoded'}, url: target_url+ '/oauth/token', data: "client_id=" + clientId + "&client_secret=" + client_secret + "&redirect_uri=" + redirect_uri + "&grant_type=authorization_code" + "&code=" + requestToken })
.then(function(data) {
deferred.resolve(data);
})
.catch(function(data, status) {
deferred.reject(data);
})
.finally(function() {
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;
}
}
passport.$inject = ['$q', '$http', '$cordovaOauthUtility'];
})();

(function() {
'use strict';

4 changes: 2 additions & 2 deletions dist/ng-cordova-oauth.min.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions src/oauth.js
Original file line number Diff line number Diff line change
@@ -45,7 +45,7 @@
'oauth.netatmo',
'oauth.trakttv',
'oauth.yahoo',
'oauth.passport'])
'oauth.laravelPassport'])
.factory("$cordovaOauth", cordovaOauth);

function cordovaOauth(
@@ -54,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, $ngCordovaPassport) {
$ngCordovaDribble, $ngCordovaPocket, $ngCordovaMercadolibre, $ngCordovaXing, $ngCordovaNetatmo, $ngCordovaTraktTv, $ngCordovaYahoo, $ngCordovaLaravelPassport) {

return {
azureAD: $ngCordovaAzureAD.signin,
@@ -98,7 +98,7 @@
netatmo: $ngCordovaNetatmo.signin,
trakttv: $ngCordovaTraktTv.signin,
yahoo: $ngCordovaYahoo.signin,
passport: $ngCordovaPassport
passport: $ngCordovaLaravelPassport
};
}

@@ -145,6 +145,6 @@
'$ngCordovaNetatmo',
'$ngCordovaTraktTv',
'$ngCordovaYahoo',
'$ngCordovaPassport'
'$ngCordovaLaravelPassport'
];
})();
12 changes: 6 additions & 6 deletions src/oauth.passport.js → src/oauth.laravelPassport.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
(function() {
'use strict';

angular.module('oauth.passport', ['oauth.utils'])
.factory('$ngCordovaPassport', passport);
angular.module('oauth.laravelPassport', ['oauth.utils'])
.factory('$ngCordovaLaravelPassport', laravelPassport);

function passport($q, $http, $cordovaOauthUtility) {
return { signin: oauthPassport };
function laravelPassport($q, $http, $cordovaOauthUtility) {
return { signin: oauthLaravelPassport };

/*
* Sign into the Laravel Passport service
@@ -15,7 +15,7 @@
* @param object options
* @return promise
*/
function oauthPassport(clientId, appScope, options) {
function oauthLaravelPassport(clientId, appScope, options) {
var deferred = $q.defer();
if(window.cordova) {
if($cordovaOauthUtility.isInAppBrowserInstalled()) {
@@ -65,5 +65,5 @@
return deferred.promise;
}
}
passport.$inject = ['$q', '$http', '$cordovaOauthUtility'];
laravelPassport.$inject = ['$q', '$http', '$cordovaOauthUtility'];
})();