Skip to content

Commit 5859518

Browse files
committed
Yandex & Mail.ru services
1 parent 5dd456f commit 5859518

File tree

5 files changed

+166
-4
lines changed

5 files changed

+166
-4
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ Each web service API acts independently in this library. However, when configur
7676
$cordovaOauth.foursquare(string clientId, object options);
7777
$cordovaOauth.magento(string baseUrl, string clientId, string clientSecret)
7878
$cordovaOauth.vkontakte(string clientId, array appScope)
79+
$cordovaOauth.odnoklassniki(string clientId, array appScope)
80+
$cordovaOauth.yandex(string clientId, object options) // defaults options={force_confirm: 'yes', browserWindow: 'location=no'}; error is a object, see below
81+
$cordovaOauth.mailru(string clientId, array appScope, object options) // defaults options={display: 'mobile', browserWindow: 'location=no'}; error is a object, see below
7982
$cordovaOauth.adfs(string clientId, string adfsServer, string relyingPartyId)
8083
$cordovaOauth.imgur(string clientId, object options)
8184
$cordovaOauth.spotify(string clientId, array appScope, object options)
@@ -145,7 +148,7 @@ angular.module("oauth.providers", [
145148
'oauth.linkedin', 'oauth.instagram', 'oauth.box', 'oauth.reddit', 'oauth.slack',
146149
'oauth.twitter', 'oauth.meetup', 'oauth.salesforce', 'oauth.strava',
147150
'oauth.withings', 'oauth.foursquare', 'oauth.magento', 'oauth.vkontakte',
148-
'oauth.odnoklassniki', 'oauth.imgur', 'oauth.spotify', 'oauth.uber',
151+
'oauth.odnoklassniki', 'oauth.yandex', 'oauth.mailru', 'oauth.imgur', 'oauth.spotify', 'oauth.uber',
149152
'oauth.windowslive', 'oauth.yammer', 'oauth.venmo', 'oauth.stripe', 'oauth.rally',
150153
'oauth.familySearch', 'oauth.envato', 'oauth.weibo', 'oauth.jawbone', 'oauth.untappd',
151154
'oauth.dribble', '<YOUR PROVIDER MODULE HERE>']).factory("$cordovaOauth", cordovaOauth);
@@ -154,7 +157,7 @@ function cordovaOauth(
154157
$q, $http, $cordovaOauthUtility, $azureAD, $adfs, $dropbox, $digitalOcean,
155158
$google, $github, $facebook, $linkedin, $instagram, $box, $reddit, $slack,
156159
$twitter, $meetup, $salesforce, $strava, $withings, $foursquare, $magento
157-
$vkontakte, $odnoklassniki, $imgur, $spotify, $uber, $windowslive, $yammer,
160+
$vkontakte, $odnoklassniki, $yandex, $mailru, $imgur, $spotify, $uber, $windowslive, $yammer,
158161
$venmo, $stripe, $rally, $familySearch, $envato, $weibo, $jawbone, $untappd,
159162
$dribble, <YOUR FACTORY NAME>) {
160163

@@ -169,7 +172,7 @@ $cordovaOauth.$inject = [
169172
'$digitalOcean', '$google', '$github', '$facebook', '$linkedin',
170173
'$instagram', '$box', '$reddit', '$slack', '$twitter' '$meetup', '$salesforce',
171174
'$strava', '$withings', '$foursquare', '$magento', '$vkontakte',
172-
'$odnoklassniki', '$imgur', '$spotify', '$uber', '$windowslive', '$yammer',
175+
'$odnoklassniki', '$yandex', '$mailru', '$imgur', '$spotify', '$uber', '$windowslive', '$yammer',
173176
'$venmo', '$stripe', '$rally', '$familySearch', '$envato', '$weibo',
174177
'$jawbone', '$untappd', '$dribble', '<YOUR FACTORY NAME>'
175178
];

src/oauth.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
'oauth.magento',
2626
'oauth.vkontakte',
2727
'oauth.odnoklassniki',
28+
"oauth.yandex",
29+
"oauth.mailru",
2830
'oauth.imgur',
2931
'oauth.spotify',
3032
'oauth.uber',
@@ -51,7 +53,7 @@
5153
$q, $http, $cordovaOauthUtility, $ngCordovaAzureAD, $ngCordovaAdfs, $ngCordovaDropbox, $ngCordovaDigitalOcean,
5254
$ngCordovaGoogle, $ngCordovaGithub, $ngCordovaFacebook, $ngCordovaLinkedin, $ngCordovaInstagram, $ngCordovaBox, $ngCordovaReddit, $ngCordovaSlack,
5355
$ngCordovaTwitter, $ngCordovaMeetup, $ngCordovaSalesforce, $ngCordovaStrava, $ngCordovaWithings, $ngCordovaFoursquare, $ngCordovaMagento,
54-
$ngCordovaVkontakte, $ngCordovaOdnoklassniki, $ngCordovaImgur, $ngCordovaSpotify, $ngCordovaUber, $ngCordovaWindowslive, $ngCordovaYammer,
56+
$ngCordovaVkontakte, $ngCordovaOdnoklassniki, $ngCordovaYandex, $ngCordovaMailru, $ngCordovaImgur, $ngCordovaSpotify, $ngCordovaUber, $ngCordovaWindowslive, $ngCordovaYammer,
5557
$ngCordovaVenmo, $ngCordovaStripe, $ngCordovaRally, $ngCordovaFamilySearch, $ngCordovaEnvato, $ngCordovaWeibo, $ngCordovaJawbone, $ngCordovaUntappd,
5658
$ngCordovaDribble, $ngCordovaPocket, $ngCordovaMercadolibre, $ngCordovaXing, $ngCordovaNetatmo, $ngCordovaTraktTv, $ngCordovaYahoo) {
5759

@@ -77,6 +79,8 @@
7779
magento: $ngCordovaMagento.signin,
7880
vkontakte: $ngCordovaVkontakte.signin,
7981
odnoklassniki: $ngCordovaOdnoklassniki.signin,
82+
yandex: $ngCordovaYandex.signin,
83+
mailru: $ngCordovaMailru.signin,
8084
imgur: $ngCordovaImgur.signin,
8185
spotify: $ngCordovaSpotify.signin,
8286
uber: $ngCordovaUber.signin,
@@ -123,6 +127,8 @@
123127
'$ngCordovaMagento',
124128
'$ngCordovaVkontakte',
125129
'$ngCordovaOdnoklassniki',
130+
'$ngCordovaYandex',
131+
'$ngCordovaMailru',
126132
'$ngCordovaImgur',
127133
'$ngCordovaSpotify',
128134
'$ngCordovaUber',

src/oauth.mailru.js

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
(function() {
2+
'use strict';
3+
4+
angular.module('oauth.mailru', ['oauth.utils'])
5+
.factory('$ngCordovaMailru', mailru);
6+
7+
function mailru($q, $cordovaOauthUtility) {
8+
return { signin: oauthMailru };
9+
10+
/*
11+
* Sign into the Mail.ru service
12+
*
13+
* @param string clientId
14+
* @param array appScope (optional)
15+
* @param object options (defaults {
16+
display: 'mobile',
17+
browserWindow: 'location=no' // see http://cordova.apache.org/docs/en/latest/reference/cordova-plugin-inappbrowser/index.html#cordovainappbrowseropen
18+
})
19+
* @return promise
20+
*
21+
*
22+
* Required:
23+
* <meta http-equiv="Content-Security-Policy" content="default-src 'self' https://connect.mail.ru/ ... ">
24+
*/
25+
function oauthMailru(clientId, appScope, options) {
26+
var deferred = $q.defer();
27+
if(window.cordova) {
28+
if($cordovaOauthUtility.isInAppBrowserInstalled()) {
29+
if(options === undefined) { options = {}; }
30+
if(appScope === undefined) { appScope = []; }
31+
if( !options.hasOwnProperty("redirect_uri") ) {
32+
options.redirect_uri = "http://connect.mail.ru/oauth/success.html"; // http://localhost/callback
33+
//~ deferred.reject({error: "You must set option redirect_uri that is an any url within YOUR DOMAIN! The redirect_uri:'http://localhost/callback' doesnt works."});
34+
//~ return deferred.promise;
35+
}
36+
if( !options.hasOwnProperty("display") ) {
37+
options.display = "mobile";
38+
}
39+
if( !options.hasOwnProperty("browserWindow") ) {
40+
options.browserWindow = "location=no";
41+
}
42+
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(" ");
43+
44+
var browserRef = window.cordova.InAppBrowser.open(flowUrl, '_blank', options.browserWindow);
45+
browserRef.addEventListener('loadstart', function(event) {
46+
if((event.url).indexOf(options.redirect_uri) === 0) {
47+
browserRef.removeEventListener("exit",function(event){});
48+
browserRef.close();
49+
var callbackResponse = (event.url).split("#")[1];
50+
var responseParameters = (callbackResponse).split("&");
51+
var parameterMap = {};
52+
for(var i = 0; i < responseParameters.length; i++) {
53+
var splitParam = responseParameters[i].split("=");
54+
parameterMap[splitParam[0]] = splitParam[1];
55+
}
56+
if(parameterMap.access_token !== undefined && parameterMap.access_token !== null) {
57+
deferred.resolve(parameterMap);
58+
} else {
59+
deferred.reject(parameterMap);
60+
}
61+
}
62+
});
63+
browserRef.addEventListener('exit', function(event) {
64+
deferred.reject({error: "The sign in flow was canceled"});
65+
});
66+
} else {
67+
deferred.reject({error: "Could not find InAppBrowser plugin"});
68+
}
69+
} else {
70+
deferred.reject({error: "Cannot authenticate via a web browser"});
71+
}
72+
73+
return deferred.promise;
74+
}
75+
}
76+
77+
mailru.$inject = ['$q', '$cordovaOauthUtility'];
78+
})();

src/oauth.yandex.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
(function() {
2+
'use strict';
3+
4+
angular.module('oauth.yandex', ['oauth.utils'])
5+
.factory('$ngCordovaYandex', yandex);
6+
7+
function yandex($q, $cordovaOauthUtility) {
8+
return { signin: oauthYandex };
9+
10+
/*
11+
* Sign into the Yandex service
12+
*
13+
* @param string clientId
14+
* @param object options (defaults {
15+
force_confirm: 'yes', // allow account change
16+
browserWindow: 'location=no' // see http://cordova.apache.org/docs/en/latest/reference/cordova-plugin-inappbrowser/index.html#cordovainappbrowseropen
17+
})
18+
* @return promise
19+
*
20+
* Required:
21+
* <meta http-equiv="Content-Security-Policy" content="default-src 'self' https://oauth.yandex.ru ... ">
22+
*/
23+
function oauthYandex(clientId, options) {
24+
var deferred = $q.defer();
25+
if(window.cordova) {
26+
if($cordovaOauthUtility.isInAppBrowserInstalled()) {
27+
if(options === undefined) { options = {}; }
28+
if( !options.hasOwnProperty("redirect_uri") ) {
29+
options.redirect_uri = "http://localhost/callback";
30+
}
31+
if( !options.hasOwnProperty("force_confirm") ) {
32+
options.force_confirm = "yes";
33+
}
34+
if( !options.hasOwnProperty("browserWindow") ) {
35+
options.browserWindow = "location=no";
36+
}
37+
var flowUrl = "https://oauth.yandex.ru/authorize?response_type=token&client_id=" + clientId + "&redirect_uri=" + options.redirect_uri + "&force_confirm=" + options.force_confirm;
38+
39+
var browserRef = window.cordova.InAppBrowser.open(flowUrl, '_blank', options.browserWindow);
40+
browserRef.addEventListener('loadstart', function(event) {
41+
if((event.url).indexOf(options.redirect_uri) === 0) {
42+
browserRef.removeEventListener("exit",function(event){});
43+
browserRef.close();
44+
var callbackResponse = (event.url).split("#")[1];
45+
var responseParameters = (callbackResponse).split("&");
46+
var parameterMap = {};
47+
for(var i = 0; i < responseParameters.length; i++) {
48+
var splitParam = responseParameters[i].split("=");
49+
parameterMap[splitParam[0]] = splitParam[1];
50+
}
51+
if(parameterMap.access_token !== undefined && parameterMap.access_token !== null) {
52+
deferred.resolve(parameterMap);
53+
} else {
54+
deferred.reject(parameterMap);
55+
}
56+
}
57+
});
58+
browserRef.addEventListener('exit', function(event) {
59+
deferred.reject("The sign in flow was canceled");
60+
});
61+
} else {
62+
deferred.reject("Could not find InAppBrowser plugin");
63+
}
64+
} else {
65+
deferred.reject("Cannot authenticate via a web browser");
66+
}
67+
68+
return deferred.promise;
69+
}
70+
}
71+
72+
yandex.$inject = ['$q', '$cordovaOauthUtility'];
73+
})();

src/plugin.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
* Magento
4040
* vkontakte
4141
* Odnoklassniki
42+
* Yandex
43+
* Mail.ru
4244
* ADFS
4345
* Imgur
4446
* Spotify

0 commit comments

Comments
 (0)