i am using Facebook authentication of webapi 2 mvc anguler.js, Mvc fb login successfully. ut when i logout from facebook it working well.but when tried to login another fb a/c cache remain in bower and get detail from cache or login with previous
details.
here is my logout code
Controller
$scope.logOut = function () {
authService.logOut();
var logoutWindow;
var fbToken = localStorageService.get('fbToken');
if (fbToken) {
var fblogoutUrl = 'https://www.facebook.com/logout.php?access_token=' + fbToken + '&next=http://google.com';
logoutWindow = $window.open(fblogoutUrl, '_blank', 'location=no,toolbar=no');
$timeout(function () {
logoutWindow.close();
localStorageService.remove('fbToken');
}, 1000);
}
$route.reload();
$cacheFactory.get('$http').removeAll();
$scope.authentication = authService.authentication;
$scope.loginData.email = "";
$scope.loginData.pasword = "";
$location.path('/index');
Service
var _logOut = function () {
return $http.post(serviceBase + 'api/Account/Logout').then(function (response) {
localStorageService.remove('authorizationData');
_authentication.isAuth = false;
_authentication.userName = "";
_authentication.role = "";
_authentication.fullName = "";
_authentication.useRefreshTokens = false;
});
};
server side code
[Route("Logout")]
public IHttpActionResult Logout()
{
Authentication.SignOut(CookieAuthenticationDefaults.AuthenticationType);
return Ok();
}
What I have tried:
// Login controller
$scope.authExternalProvider = function (provider) {
var redirectUri = location.protocol + '//' + location.host + '/app/views/authComplete.html';
var externalProviderUrl = ngAuthSettings.apiServiceBaseUri + "api/Account/ExternalLogin?provider=" + provider
+ "&response_type=token&client_id=" + ngAuthSettings.clientId
+ "&redirect_uri=" + redirectUri;
$window.$windowScope = $scope;
var oauthWindow = $window.open(externalProviderUrl, "Authenticate Account", "location=0,status=0,width=600,height=750");
};
$scope.authCompletedCB = function (fragment) {
console.log(fragment);
if (fragment && fragment.external_access_token)
localStorageService.set('fbToken', fragment.external_access_token);
$scope.$apply(function () {
var externalData = { provider: fragment.provider, externalAccessToken: fragment.external_access_token };
authService.obtainAccessToken(externalData).then(function (response) {
$scope.authentication = authService.authentication;
$location.path('/index');
},
function (err) {
$scope.message = err.Message;
if (fragment.haslocalaccount == 'False') {
authService.logOut();
authService.externalAuthData = {
provider: fragment.provider,
userName: fragment.external_user_name,
externalAccessToken: fragment.external_access_token,
email: fragment.external_email
};
if (authService.externalAuthData.email == undefined || authService.externalAuthData.email == "" || authService.externalAuthData.email == null) {
$location.path('/associate');
} else {
$controller('associateController', { $scope: $scope })
$scope.registerExternal();
}
}
});
});
}
//associate
app.controller('associateController', ['$scope', '$location', '$timeout', 'authService', '$controller', function ($scope, $location, $timeout, authService, $controller) {
$scope.savedSuccessfully = false;
$scope.message = "";
$scope.registerData = {
email: authService.externalAuthData.email,
userName: authService.externalAuthData.userName,
provider: authService.externalAuthData.provider,
externalAccessToken: authService.externalAuthData.externalAccessToken
};
$scope.registerExternal = function () {
//$scope.registerData.email = authService.externalAuthData.userName;
authService.registerExternal($scope.registerData).then(function (response) {
$scope.savedSuccessfully = true;
alert("Successfully authenticated by facebook");
// $scope.message = "User has been registered successfully, you will be redicted to orders page in 2 seconds.";
// startTimer();
$scope.authentication = authService.authentication;
$location.path('/index');
},
function (response) {
var errors = [];
for (var key in response.ModelState) {
errors.push(response.ModelState[key]);
}
$scope.message = "Failed to register user due to:" + " Email '" + $scope.registerData.email + "' is already taken.";
});
};
var startTimer = function () {
var timer = $timeout(function () {
$timeout.cancel(timer);
$location.path('/index');
}, 2000);
}
}]);