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

Yandex & Mail.ru services #301

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
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) // defaults options={force_confirm: 'yes', browserWindow: 'location=no'}; error is a object, see below
$cordovaOauth.mailru(string clientId, array appScope, object options) // defaults options={display: 'mobile', browserWindow: 'location=no'}; 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
78 changes: 78 additions & 0 deletions src/oauth.mailru.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
(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',
browserWindow: 'location=no' // see http://cordova.apache.org/docs/en/latest/reference/cordova-plugin-inappbrowser/index.html#cordovainappbrowseropen
})
* @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://connect.mail.ru/oauth/success.html"; // http://localhost/callback
//~ 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."});
//~ return deferred.promise;
}
if( !options.hasOwnProperty("display") ) {
options.display = "mobile";
}
if( !options.hasOwnProperty("browserWindow") ) {
options.browserWindow = "location=no";
}
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', options.browserWindow);
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++) {
var splitParam = responseParameters[i].split("=");
parameterMap[splitParam[0]] = splitParam[1];
}
if(parameterMap.access_token !== undefined && parameterMap.access_token !== null) {
deferred.resolve(parameterMap);
} else {
deferred.reject(parameterMap);
}
}
});
browserRef.addEventListener('exit', function(event) {
deferred.reject({error: "The sign in flow was canceled"});
});
} else {
deferred.reject({error: "Could not find InAppBrowser plugin"});
}
} else {
deferred.reject({error: "Cannot authenticate via a web browser"});
}

return deferred.promise;
}
}

mailru.$inject = ['$q', '$cordovaOauthUtility'];
})();
73 changes: 73 additions & 0 deletions src/oauth.yandex.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
(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', // allow account change
browserWindow: 'location=no' // see http://cordova.apache.org/docs/en/latest/reference/cordova-plugin-inappbrowser/index.html#cordovainappbrowseropen
})
* @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";
}
if( !options.hasOwnProperty("browserWindow") ) {
options.browserWindow = "location=no";
}
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', options.browserWindow);
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++) {
var splitParam = responseParameters[i].split("=");
parameterMap[splitParam[0]] = splitParam[1];
}
if(parameterMap.access_token !== undefined && parameterMap.access_token !== null) {
deferred.resolve(parameterMap);
} else {
deferred.reject(parameterMap);
}
}
});
browserRef.addEventListener('exit', function(event) {
deferred.reject({error: "The sign in flow was canceled"});
});
} else {
deferred.reject({error: "Could not find InAppBrowser plugin"});
}
} else {
deferred.reject({error: "Cannot authenticate via a web browser"});
}

return deferred.promise;
}
}

yandex.$inject = ['$q', '$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