class SmsCandy::Authentication::Strategies::OAuth2

Attributes

access_token[R]
expires_at[R]

Public Instance Methods

authenticate!() click to toggle source

curl “api.telstra.com/v1/oauth/token?client_id=$APP_KEY&client_secret=$APP_SECRET&grant_type=client_credentials&scope=SMS

# File lib/sms_candy/authentication/strategies/o_auth_2.rb, line 16
def authenticate!
  response = RestClient.get(base_url, { params: authentication_params })

  json_response = JSON.parse response.body
  @expires_at = Time.zone.now + json_response["expires_in"].to_i
  @access_token = json_response["access_token"]
end

Private Instance Methods

authentication_params() click to toggle source
# File lib/sms_candy/authentication/strategies/o_auth_2.rb, line 26
def authentication_params
  {
    client_id: ENV["TELSTRA_SMS_CLIENT_ID"],
    client_secret: ENV["TELSTRA_SMS_CLIENT_SECRET"],
    grant_type: ENV["TELSTRA_SMS_GRANT_TYPE"],
    scope: ENV["TELSTRA_SMS_SCOPE"]
  }
end
base_url() click to toggle source
# File lib/sms_candy/authentication/strategies/o_auth_2.rb, line 35
def base_url
  SmsCandy::Config.base_url + "oauth/token"
end