Nitin Nitin - 6 months ago 142
jQuery Question

Angularjs login twitter and linkedin custom without oath0 third party service

i have developed application in angular and i am done with facebook login custom without using Oath0 third party service.
i am done with login twitter with Oath service but not found any solution without Oath0 third party service.
So, is there any idea for the linkedin and twitter login in angular without using Oath0 third party service?

Answer

Here is example of twitter and linkedin login in your app module configuration make sure you have added ngsanitize

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

in your controller file in login controller

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;
    });
}});

now i have implemented linkedin login with jqery and pass data to angular function.below is code for linkedin login with js sdk. add javascript file to your html.

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

IN your controller file

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);
}

for linkedin you have to call controller from your html using ng-controller this is the only way to make it work. you need to download oauth.js file from below link oauth.js file for twitter auth

Comments