Angularjs 在没有 oath0 第三方服务的情况下登录 twitter 和 linkedin 自定义

Angularjs login twitter and linkedin custom without oath0 third party service

我已经在 angular 中开发了应用程序,并且我在不使用 Oath0 第三方服务的情况下完成了 Facebook 登录自定义。 我已经完成了使用 Oath 服务登录 Twitter,但没有找到没有 Oath0 第三方服务的任何解决方案。 那么,在不使用 Oath0 第三方服务的情况下,angular 中的 linkedin 和 twitter 登录有什么想法吗?

至少对于 Twitter,我可以告诉您,如果没有 OAuth,您很可能无法进行身份验证。

Twitter username/password 身份验证对于特定的业务案例和准备为此付费的公司受到严格限制。据我所知,唯一可以使用此功能的应用是 instagram。

您可以提出此功能的请求,但为了与团队密切合作,如果您没有大公司支持您的请求,则有 99% 的机会被拒绝。

为了加强我的观点,我想说我是 Twitter 第三方库的开发人员,在与他们的员工就这个特定主题会面时,他们告诉我我不应该添加 username/password 对图书馆进行身份验证,因为拥有此类权限的客户数量非常有限。

这里是 Twitter 和 linkedin 登录的例子。在您的应用程序模块配置中,确保您已添加 ngsanitize

var app = angular.module("app", ['ngRoute', 'ngMessages','ngCookies','ngSanitize']);

在你的控制器文件中

在登录控制器中

app.controller("loginsController", function ($location, $scope, $http, $rootScope, constant,$q,twitterService) {
twitterService.initialize();
$scope.LinkedfoundMe = function (me) {
    $scope.me = me;
    $scope.$digest();
    $scope.LoginSocialUsers($scope.me);
};
$scope.connectTWButton = function() {
    twitterService.connectTwitter().then(function() {
        if (twitterService.isReady()) {
            //if the authorization is successful, hide the connect button and display the tweets
               $scope.refreshTimeline();

            $scope.connectedTwitter = true;
        } else {
         }
    });
}
 $scope.refreshTimeline = function() {
    twitterService.getTweetUser().then(function(data) {
        if(data[0].user.id != null || data[0].user.id != undefined){
            var TwData = {};
           TwData.firstName =data[0].user.name; 
           TwData.lastName =""; 
           TwData.emailAddress =""; 
           TwData.id =data[0].user.id; 
            $scope.LoginSocialUsers(TwData);
        }
    },function(){
        $scope.rateLimitError = true;
    });
}});

现在我已经实现了 linkedin 登录 jQuery 并将数据传递给 angular 功能。以下是 linkedin 使用 js sdk 登录的代码。

将 javascript 文件添加到您的 html。

<script type="text/javascript" src="http://platform.linkedin.com/in.js">
 api_key: YOUR_APP_KEY 
 onLoad: displayLinkedInLogin 
 authorize: false  
 </script>

在你的控制器文件中

function linkedAuthLink() {
IN.User.authorize(function () {
});
}
function displayLinkedInLogin() {
IN.Event.on(IN, "auth", onLinkedInAuth);
}
function onLinkedInAuth() {
IN.API.Profile("me")
        .fields(["firstName", "lastName", "emailAddress",       "pictureUrl", "id", "headline", "location", "summary", "positions", "twitter-accounts"])
        .result(displayProfiles);
}
function displayProfiles(profiles, $scope) {
member = profiles.values[0];
angular.element($("#logincontroller")).scope().LinkedfoundMe(member);
}

对于 linkedin 你必须使用 ng-controller 从你的 html 调用控制器,这是让它工作的唯一方法。 您需要从下面下载 oauth.js 文件 link oauth.js file for twitter auth