简体   繁体   English

FIWARE Keyrock OAuth回调-红宝石

[英]FIWARE keyrock oauth callback - ruby

I am trying to implement/use Fiware Keyrock for authentization. 我正在尝试实施/使用Fiware Keyrock进行身份验证。 Is there any tutorial/webinar on how to do it. 是否有任何有关如何操作的教程/网络研讨会。 Anyone does this ? 有人吗? It requires callbackurl and url of application of oauth, how to implement this in my rails application that it would communicate with keyrock (IDM). 它需要callbackurl和oauth应用程序的URL,以及如何在将与Keyrock(IDM)通信的Rails应用程序中实现此功能。 Any help is greatly appreciated, Thank you. 非常感谢您的任何帮助,谢谢。

I have done this using the omniauth gem and using oauth2. 我已经使用omniauth gem和oauth2做到了这一点。 There are several tutorials for using omniauth. 有一些使用omniauth的教程。 You can first try another provider, like twitter. 您可以先尝试使用其他提供商,例如twitter。

I have created a "strategy" like this and placed it into /lib/omni_auth/strategies/filab_strategy.rb 我已经创建了这样的“策略”,并将其放入/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. 然后,我以配置其他更多主流策略的方式进行配置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM