forked from jacknudt/trustieforge
38 lines
663 B
Ruby
38 lines
663 B
Ruby
#coding=utf-8
|
|
|
|
require 'base64'
|
|
require 'json'
|
|
require 'openssl'
|
|
|
|
## 单点登录 <=> 北斗
|
|
class SsoController < ApplicationController
|
|
|
|
def index
|
|
options = parse(params[:auth])
|
|
|
|
logger.debug options
|
|
|
|
## 认证
|
|
login(options[:id])
|
|
|
|
## 选择性跳转
|
|
|
|
redirect_to Organization.find(82)
|
|
|
|
end
|
|
|
|
private
|
|
def parse(auth)
|
|
crypted_str = Base64.decode64(auth)
|
|
pkey = OpenSSL::PKey::RSA.new(File.new(File.join(Rails.root,"config/private.key")))
|
|
content = pkey.private_decrypt(pwd,OpenSSL::PKey::RSA::NO_PADDING)
|
|
JSON.parser(content)
|
|
end
|
|
|
|
def login(id)
|
|
sso = Sso.find(id)
|
|
start_user_session(sso.user)
|
|
end
|
|
|
|
end
|