Class: OmniAuth::Strategies::Chatwork

Inherits:
OAuth2
  • Object
show all
Defined in:
lib/omniauth/strategies/chatwork.rb

Constant Summary collapse

DEFAULT_SCOPE =
"rooms.all:read_write users.profile.me:read"

Instance Method Summary collapse

Instance Method Details

#access_token_callback_urlObject



63
64
65
66
67
# File 'lib/omniauth/strategies/chatwork.rb', line 63

def access_token_callback_url
  # Remove query string from OmniAuth::Strategy#callback_url
  # https://github.com/omniauth/omniauth/blob/v1.7.1/lib/omniauth/strategy.rb#L438-L440
  options[:callback_url] || (full_host + script_name + callback_path)
end

#authorize_paramsObject

You can pass scope params to the auth request, if you need to set them dynamically. You can also set these options in the OmniAuth config :authorize_params option.

For example: /auth/chatwork?scope=rooms.all:read_write



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/omniauth/strategies/chatwork.rb', line 45

def authorize_params
  super.tap do |params|
    %w[scope].each do |v|
      if request.params[v]
        params[v.to_sym] = request.params[v]
      end
    end

    params[:scope] ||= DEFAULT_SCOPE
    params[:scope] = Array(params[:scope]).join(" ")
  end
end

#build_access_tokenObject



58
59
60
61
# File 'lib/omniauth/strategies/chatwork.rb', line 58

def build_access_token
  verifier = request.params["code"]
  client.auth_code.get_token(verifier, {:redirect_uri => access_token_callback_url}.merge(token_params.to_hash(:symbolize_keys => true)), deep_symbolize(options.auth_token_params))
end

#raw_infoObject



37
38
39
# File 'lib/omniauth/strategies/chatwork.rb', line 37

def raw_info
  @raw_info ||= access_token.get("me").parsed || {}
end