FIWARE keyrock oauth回调 - ruby

时间:2015-06-26 18:30:56

标签: ruby callback oauth-2.0 fiware

我正在尝试实施/使用Fiware Keyrock进行身份验证。有没有关于如何做的教程/网络研讨会。有人这样做吗?它需要oeuth的callbackurl和url应用程序,如何在我的rails应用程序中实现它,它将与keyrock(IDM)进行通信。非常感谢任何帮助,谢谢。

1 个答案:

答案 0 :(得分:0)

I have done this using the omniauth gem and using oauth2. There are several tutorials for using omniauth. You can first try another provider, like twitter.

I have created a "strategy" like this and placed it into /lib/omni_auth/strategies/filab_strategy.rb

require 'omniauth-oauth2'
module OmniAuth
  module Strategies
    class FilabStrategy < OmniAuth::Strategies::OAuth2
      option :name, "filab"
      option :client_options, {
          :site => 'https://account.lab.fiware.org',
          :authorize_url => 'https://account.lab.fiware.org/oauth2/authorize',
          :token_url => 'https://account.lab.fiware.org/oauth2/token'
      }

      uid { raw_info['id'].to_s }

      info do
        {
            'nickname' => raw_info['nickName'],
            'displayName' => raw_info['displayName'],
            'email' => raw_info['email'],
            'name' => raw_info['displayName'],
        }
      end

      extra do
        {:raw_info => raw_info}
      end

      def raw_info
        access_token.options[:mode] = :query
        @raw_info ||= access_token.get('user.json', params: { access_token: access_token.token }).parsed
      end
    end
  end
end

Then I configured and it the same way other more mainstream strategies are configured.