Skip to content

Commit

Permalink
Yandex & Mail.ru services
Browse files Browse the repository at this point in the history
  • Loading branch information
mche committed Oct 30, 2016
1 parent 5dd456f commit 7feb3d7
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 4 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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', '<YOUR PROVIDER MODULE HERE>']).factory("$cordovaOauth", cordovaOauth);
Expand All @@ -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, <YOUR FACTORY NAME>) {

Expand All @@ -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', '<YOUR FACTORY NAME>'
];
Expand Down
8 changes: 7 additions & 1 deletion src/oauth.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
'oauth.magento',
'oauth.vkontakte',
'oauth.odnoklassniki',
"oauth.yandex",
"oauth.mailru",
'oauth.imgur',
'oauth.spotify',
'oauth.uber',
Expand All @@ -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) {

Expand All @@ -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,
Expand Down Expand Up @@ -123,6 +127,8 @@
'$ngCordovaMagento',
'$ngCordovaVkontakte',
'$ngCordovaOdnoklassniki',
'$ngCordovaYandex',
'$ngCordovaMailru',
'$ngCordovaImgur',
'$ngCordovaSpotify',
'$ngCordovaUber',
Expand Down
69 changes: 69 additions & 0 deletions src/oauth.mailru.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
(function() {
'use strict';

angular.module('oauth.mailru', ['oauth.utils'])
.factory('$ngCordovaMailru', mailru);

function mailru($q, $http, $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:
* <meta http-equiv="Content-Security-Policy" content="default-src 'self' https://connect.mail.ru/ ... ">
*/
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', '$http', '$cordovaOauthUtility'];
})();
67 changes: 67 additions & 0 deletions src/oauth.yandex.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
(function() {
'use strict';

angular.module('oauth.yandex', ['oauth.utils'])
.factory('$ngCordovaYandex', yandex);

function yandex($q, $http, $cordovaOauthUtility) {
return { signin: oauthYandex };

/*
* Sign into the Yandex service
*
* @param string clientId
* @param object options (defaults force_confirm:'yes')
* @return promise
*
* Required:
* <meta http-equiv="Content-Security-Policy" content="default-src 'self' https://oauth.yandex.ru ... ">
*/
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', '$http', '$cordovaOauthUtility'];
})();
2 changes: 2 additions & 0 deletions src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
* Magento
* vkontakte
* Odnoklassniki
* Yandex
* Mail.ru
* ADFS
* Imgur
* Spotify
Expand Down

0 comments on commit 7feb3d7

Please sign in to comment.