require 'omniauth-oauth2' module OmniAuth module Strategies class Inspur < OmniAuth::Strategies::OAuth2 option :name, 'inspur' option :client_options, { site: 'https://inspur.com', authorize_url: '/oauth/authorize', token_url: '/oauth/token', user_info_url: '/admin/system/user/getUserInfo', } option :redirect_url uid { raw_info['userId'].to_s } info do { name: raw_info['userName'], username: raw_info['loginName'], email: raw_info['email'] } end extra do { raw_info: raw_info } end def raw_info @raw_info ||= access_token.get(option.client_options.user_info_url, headers: { 'Content-type': 'application/json', 'token': "#{access_token.token}", }).parsed end def email (raw_info['email']) ? raw_info['email'] : "#{raw_info['loginName']}@indata.com" end private def callback_url options.redirect_url || (full_host + script_name + callback_path) end end end end OmniAuth.config.add_camelization 'inspur', 'Inspur'