-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
169 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
(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 | ||
* | ||
* NOTE! В значении параметра redirect_uri передайте адрес страницы, | ||
* на которую будет происходить перенаправление пользователя после авторизации. | ||
* Эта страница ДОЛЖНА НАХОДИТЬСЯ НА ДОМЕНЕ ВАШЕГО САЙТА. | ||
* | ||
* 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 | ||
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);//,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']; | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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);//,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']; | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,8 @@ | |
* Magento | ||
* vkontakte | ||
* Odnoklassniki | ||
* Yandex | ||
* Mail.ru | ||
* ADFS | ||
* Imgur | ||
* Spotify | ||
|