Skip to content

Work with JWT's #76

Description

@mick26

Hello,
I am trying to make angular-socket.io work with an JWT Authentication system (using socketio-jwt and jsonwebtoken packages). I am using socket.io V1. I have the following angular service which sends the JWT as a query string. Socket authentication only works in my program when I log on and then hit F5. I am assuming this is because the Provider service wraps around the io() object and creates the socketFactory factory service when the program starts. Thus the factory Service is created before a user logs on and is given a JWT by the Node server. I have tried doing explicit refreshing and making other $http requests in the controller like:
$http.get("http://localhost:4000/socket.io/?token="+token")
$http.get("ws://localhost:4000/socket.io/?token="+token")
$window.location.reload();

How would angular-socket-io be hooked up to an authentication system where the io.connect querystring parameter varies with each login? Are there any examples?

angular.module('myApp.services', [])
.factory('socket', function (socketFactory, $rootScope, $window) {
  return socketFactory({
    ioSocket: io.connect('http://localhost:4000', {
      'force new connection': true, query: 'token=' + $window.sessionStorage.token
    })
  });
});

Many Thanks
Mick

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions