var Strategy = require('../lib/strategy')
  , chai = require('chai')
  , qs = require('querystring');

describe('strategy', function() {

  describe('configured to work with a specific OpenID provider', function() {

    describe('issuing authorization request', function() {

      describe('that redirects to service provider without redirect URI', function() {
        var strategy = new Strategy({
          authorizationURL: 'https://www.example.com/oauth2/authorize',
          tokenURL: 'https://www.example.com/oauth2/token',
          clientID: 'ABC123',
          clientSecret: 'secret'
        },
        function(accessToken, refreshToken, profile, done) {});
      
      
        var state, url;
  
        before(function(done) {
          chai.passport.use(strategy)
            .redirect(function(u) {
              state = encodeURIComponent(qs.parse(u).state);
              url = u;
              done();
            })
            .req(function(req) {
              req.session = {};
            })
            .authenticate();
        });
  
        it('should be redirected', function() {
          expect(url).to.equal('https://www.example.com/oauth2/authorize?response_type=code&client_id=ABC123&scope=openid&state=' + state);
        });
      }); // that redirects to service provider without redirect URI
  
    }); // issuing authorization request
    
  }); // configured to work with a known OpenID provider
  
}); // Strategy

@@ -62,16 +62,41 @@
 'chai')%0A
+  , uri = require('url')%0A
   , qs =
@@ -420,16 +420,61 @@
 ategy(%7B%0A
+          issuer: 'https://www.example.com',%0A
         
@@ -670,24 +670,16 @@
       %7D,
-%0A       
  functio
@@ -684,48 +684,8 @@
 ion(
-accessToken, refreshToken, profile, done
 ) %7B%7D
@@ -717,18 +717,27 @@
 var 
+request, url, 
 state
-, url
 ;%0A  
@@ -861,53 +861,88 @@
     
-state = encodeURIComponent(qs.parse(u)
+var pu = uri.parse(u, true);%0A              %0A              state = pu.query
 .state
-)
 ;%0A  
@@ -1028,24 +1028,53 @@
 tion(req) %7B%0A
+              request = req;%0A
             
@@ -1332,16 +1332,296 @@
 ate=' + 
+encodeURIComponent(state));%0A        %7D);%0A        %0A        it('should save state in session', function() %7B%0A          expect(request.session%5B'openidconnect:www.example.com'%5D.state).to.have.length(24);%0A          expect(request.session%5B'openidconnect:www.example.com'%5D.state).to.equal(
 state);%0A

Update test case.