'use strict';

var crypto = require('crypto');
var config = require('./../config');

module.exports = function*(next) {
  this.session.state = crypto.randomBytes(32).toString('hex');

  yield this.render('login.ect', {
    uri: this.sso.authorization().authorizeUri({
      redirect_uri: config.redirectUri,
      state: this.session.state,
      prompt: 'login consent',
      scope: this.sso._config.get('default_scopes') + ' offline_access'

    }),
    callbackUri: config.redirectUri
  });

  yield next;
};
