Class: OmniAuth::Strategies::Mhealth

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

Defined Under Namespace

Classes: NoAuthorizationCodeError

Constant Summary collapse

DEFAULT_SCOPE =
'/read/health/user'

Instance Method Summary collapse

Instance Method Details

#authorize_paramsObject



52
53
54
55
56
# File 'lib/omniauth-mhealth/strategies/mhealth.rb', line 52

def authorize_params
  super.tap do |params|
    params[:scope] ||= DEFAULT_SCOPE
  end
end

#build_access_tokenObject



58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/omniauth-mhealth/strategies/mhealth.rb', line 58

def build_access_token
  ssl_options = options.client_options[:ssl].to_hash.symbolize_keys rescue {}
  token_client = Faraday.new url: options.client_options[:site], ssl: ssl_options
  post_params = {
    grant_type: 'authorization_code',
    code: request.params['code'],
    redirect_uri: self.callback_url,
  }
  auth = "Basic #{Base64.encode64([options.client_id, options.client_secret].join(':')).gsub("\n", '')}"
  resp = token_client.post('/access_token.json', post_params, 'Authorization'=>auth)
  decoded = MultiJson.decode resp.body
  self.access_token = ::OAuth2::AccessToken.from_hash client, decoded.merge(access_token_options)
end

#raw_infoObject



47
48
49
50
# File 'lib/omniauth-mhealth/strategies/mhealth.rb', line 47

def raw_info
  url = options.api_site + 'v2/health/user'
  @raw_info ||= access_token.get(url).parsed || { }
end