diff --git a/README.md b/README.md index 4adb551..503d7d6 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,9 @@ Each web service API acts independently in this library. However, when configur $cordovaOauth.foursquare(string clientId, object options); $cordovaOauth.magento(string baseUrl, string clientId, string clientSecret) $cordovaOauth.vkontakte(string clientId, array appScope) + $cordovaOauth.odnoklassniki(string clientId, array appScope) + $cordovaOauth.yandex(string clientId, object options) // default options.force_confirm='yes'; error is a object, see below + $cordovaOauth.mailru(string clientId, array appScope, object options) // default options.display='mobile'; error is a object, see below $cordovaOauth.adfs(string clientId, string adfsServer, string relyingPartyId) $cordovaOauth.imgur(string clientId, object options) $cordovaOauth.spotify(string clientId, array appScope, object options) @@ -145,7 +148,7 @@ angular.module("oauth.providers", [ 'oauth.linkedin', 'oauth.instagram', 'oauth.box', 'oauth.reddit', 'oauth.slack', 'oauth.twitter', 'oauth.meetup', 'oauth.salesforce', 'oauth.strava', 'oauth.withings', 'oauth.foursquare', 'oauth.magento', 'oauth.vkontakte', - 'oauth.odnoklassniki', 'oauth.imgur', 'oauth.spotify', 'oauth.uber', + 'oauth.odnoklassniki', 'oauth.yandex', 'oauth.mailru', 'oauth.imgur', 'oauth.spotify', 'oauth.uber', 'oauth.windowslive', 'oauth.yammer', 'oauth.venmo', 'oauth.stripe', 'oauth.rally', 'oauth.familySearch', 'oauth.envato', 'oauth.weibo', 'oauth.jawbone', 'oauth.untappd', 'oauth.dribble', '']).factory("$cordovaOauth", cordovaOauth); @@ -154,7 +157,7 @@ function cordovaOauth( $q, $http, $cordovaOauthUtility, $azureAD, $adfs, $dropbox, $digitalOcean, $google, $github, $facebook, $linkedin, $instagram, $box, $reddit, $slack, $twitter, $meetup, $salesforce, $strava, $withings, $foursquare, $magento - $vkontakte, $odnoklassniki, $imgur, $spotify, $uber, $windowslive, $yammer, + $vkontakte, $odnoklassniki, $yandex, $mailru, $imgur, $spotify, $uber, $windowslive, $yammer, $venmo, $stripe, $rally, $familySearch, $envato, $weibo, $jawbone, $untappd, $dribble, ) { @@ -169,7 +172,7 @@ $cordovaOauth.$inject = [ '$digitalOcean', '$google', '$github', '$facebook', '$linkedin', '$instagram', '$box', '$reddit', '$slack', '$twitter' '$meetup', '$salesforce', '$strava', '$withings', '$foursquare', '$magento', '$vkontakte', - '$odnoklassniki', '$imgur', '$spotify', '$uber', '$windowslive', '$yammer', + '$odnoklassniki', '$yandex', '$mailru', '$imgur', '$spotify', '$uber', '$windowslive', '$yammer', '$venmo', '$stripe', '$rally', '$familySearch', '$envato', '$weibo', '$jawbone', '$untappd', '$dribble', '' ]; diff --git a/src/oauth.js b/src/oauth.js index 60ab218..0115365 100644 --- a/src/oauth.js +++ b/src/oauth.js @@ -25,6 +25,8 @@ 'oauth.magento', 'oauth.vkontakte', 'oauth.odnoklassniki', + "oauth.yandex", + "oauth.mailru", 'oauth.imgur', 'oauth.spotify', 'oauth.uber', @@ -51,7 +53,7 @@ $q, $http, $cordovaOauthUtility, $ngCordovaAzureAD, $ngCordovaAdfs, $ngCordovaDropbox, $ngCordovaDigitalOcean, $ngCordovaGoogle, $ngCordovaGithub, $ngCordovaFacebook, $ngCordovaLinkedin, $ngCordovaInstagram, $ngCordovaBox, $ngCordovaReddit, $ngCordovaSlack, $ngCordovaTwitter, $ngCordovaMeetup, $ngCordovaSalesforce, $ngCordovaStrava, $ngCordovaWithings, $ngCordovaFoursquare, $ngCordovaMagento, - $ngCordovaVkontakte, $ngCordovaOdnoklassniki, $ngCordovaImgur, $ngCordovaSpotify, $ngCordovaUber, $ngCordovaWindowslive, $ngCordovaYammer, + $ngCordovaVkontakte, $ngCordovaOdnoklassniki, $ngCordovaYandex, $ngCordovaMailru, $ngCordovaImgur, $ngCordovaSpotify, $ngCordovaUber, $ngCordovaWindowslive, $ngCordovaYammer, $ngCordovaVenmo, $ngCordovaStripe, $ngCordovaRally, $ngCordovaFamilySearch, $ngCordovaEnvato, $ngCordovaWeibo, $ngCordovaJawbone, $ngCordovaUntappd, $ngCordovaDribble, $ngCordovaPocket, $ngCordovaMercadolibre, $ngCordovaXing, $ngCordovaNetatmo, $ngCordovaTraktTv, $ngCordovaYahoo) { @@ -77,6 +79,8 @@ magento: $ngCordovaMagento.signin, vkontakte: $ngCordovaVkontakte.signin, odnoklassniki: $ngCordovaOdnoklassniki.signin, + yandex: $ngCordovaYandex.signin, + mailru: $ngCordovaMailru.signin, imgur: $ngCordovaImgur.signin, spotify: $ngCordovaSpotify.signin, uber: $ngCordovaUber.signin, @@ -123,6 +127,8 @@ '$ngCordovaMagento', '$ngCordovaVkontakte', '$ngCordovaOdnoklassniki', + '$ngCordovaYandex', + '$ngCordovaMailru', '$ngCordovaImgur', '$ngCordovaSpotify', '$ngCordovaUber', diff --git a/src/oauth.mailru.js b/src/oauth.mailru.js new file mode 100644 index 0000000..21d593f --- /dev/null +++ b/src/oauth.mailru.js @@ -0,0 +1,69 @@ +(function() { + 'use strict'; + + angular.module('oauth.mailru', ['oauth.utils']) + .factory('$ngCordovaMailru', mailru); + + function mailru($q, $cordovaOauthUtility) { + return { signin: oauthMailru }; + + /* + * Sign into the Mail.ru service + * + * @param string clientId + * @param array appScope (optional) + * @param object options (defaults display:'mobile') + * @return promise + * + * Required: + * + */ + function oauthMailru(clientId, appScope, options) { + var deferred = $q.defer(); + if(window.cordova) { + if($cordovaOauthUtility.isInAppBrowserInstalled()) { + if(options === undefined) { options = {}; } + if(appScope === undefined) { appScope = []; } + if(! options.hasOwnProperty("redirect_uri")) { + options.redirect_uri = "http://localhost/callback"; // http://connect.mail.ru/oauth/success.html + } + if(! options.hasOwnProperty("display")) { + options.display = "mobile"; + } + var flowUrl = "https://connect.mail.ru/oauth/authorize?response_type=token&client_id=" + clientId + "&redirect_uri=" + options.redirect_uri + '&display=' + options.display + '&scope=' + appScope.join(" "); + + var browserRef = window.cordova.InAppBrowser.open(flowUrl, '_blank', 'location=no');//,clearsessioncache=yes,clearcache=yes); + browserRef.addEventListener('loadstart', function(event) { + if((event.url).indexOf(options.redirect_uri) === 0) { + browserRef.removeEventListener("exit",function(event){}); + browserRef.close(); + var callbackResponse = (event.url).split("#")[1]; + var responseParameters = (callbackResponse).split("&"); + var parameterMap = {}; + for(var i = 0; i < responseParameters.length; i++) { + parameterMap[responseParameters[i].split("=")[0]] = responseParameters[i].split("=")[1]; + } + if(parameterMap.access_token !== undefined && parameterMap.access_token !== null) { + deferred.resolve(parameterMap); + } else { + //~ deferred.reject("Problem authenticating"); + deferred.reject(parameterMap); + } + } + }); + 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; + } + } + + mailru.$inject = ['$q', '$cordovaOauthUtility']; +})(); \ No newline at end of file diff --git a/src/oauth.yandex.js b/src/oauth.yandex.js new file mode 100644 index 0000000..762fc40 --- /dev/null +++ b/src/oauth.yandex.js @@ -0,0 +1,67 @@ +(function() { + 'use strict'; + + angular.module('oauth.yandex', ['oauth.utils']) + .factory('$ngCordovaYandex', yandex); + + function yandex($q, $cordovaOauthUtility) { + return { signin: oauthYandex }; + + /* + * Sign into the Yandex service + * + * @param string clientId + * @param object options (defaults force_confirm:'yes') + * @return promise + * + * Required: + * + */ + function oauthYandex(clientId, options) { + var deferred = $q.defer(); + if(window.cordova) { + if($cordovaOauthUtility.isInAppBrowserInstalled()) { + if(options === undefined) { options = {}; } + if(! options.hasOwnProperty("redirect_uri")) { + options.redirect_uri = "http://localhost/callback"; + } + if(! options.hasOwnProperty("force_confirm")) { + options.force_confirm = "yes"; + } + var flowUrl = "https://oauth.yandex.ru/authorize?response_type=token&client_id=" + clientId + "&redirect_uri=" + options.redirect_uri + "&force_confirm=" + options.force_confirm; + + var browserRef = window.cordova.InAppBrowser.open(flowUrl, '_blank', 'location=no');//,clearsessioncache=yes,clearcache=yes + browserRef.addEventListener('loadstart', function(event) { + if((event.url).indexOf(options.redirect_uri) === 0) { + browserRef.removeEventListener("exit",function(event){}); + browserRef.close(); + var callbackResponse = (event.url).split("#")[1]; + var responseParameters = (callbackResponse).split("&"); + var parameterMap = {}; + for(var i = 0; i < responseParameters.length; i++) { + parameterMap[responseParameters[i].split("=")[0]] = responseParameters[i].split("=")[1]; + } + if(parameterMap.access_token !== undefined && parameterMap.access_token !== null) { + deferred.resolve(parameterMap); + } else { + //~ deferred.reject("Problem authenticating"); + deferred.reject(parameterMap); + } + } + }); + 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; + } + } + + yandex.$inject = ['$q', '$cordovaOauthUtility']; +})(); \ No newline at end of file diff --git a/src/plugin.js b/src/plugin.js index 8bbe637..a58b494 100644 --- a/src/plugin.js +++ b/src/plugin.js @@ -39,6 +39,8 @@ * Magento * vkontakte * Odnoklassniki + * Yandex + * Mail.ru * ADFS * Imgur * Spotify