Advertisement
Guest User

Untitled

a guest
Jul 12th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. function logout() {
  2.  
  3. // To invalidate a basic auth login:
  4. //
  5. // 1. Call this logout function.
  6. // 2. It makes a GET request to an URL with false Basic Auth credentials
  7. // 3. The URL returns a 401 Unauthorized
  8. // 4. Forward to some "you-are-logged-out"-page
  9. // 5. Done, the Basic Auth header is invalid now
  10.  
  11. jQuery.ajax({
  12. type: "GET",
  13. url: "/myapp/logout",
  14. async: false,
  15. username: "logmeout",
  16. password: "123456",
  17. headers: { "Authorization": "Basic xxx" }
  18. })
  19. .done(function(){
  20. // If we don't get an error, we actually got an error as we expect an 401!
  21. })
  22. .fail(function(){
  23. // We expect to get an 401 Unauthorized error! In this case we are successfully
  24. // logged out and we redirect the user.
  25. window.location = "/myapp/index.html";
  26. });
  27.  
  28. return false;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement