class Frameio::Auth

Constants

AUTH_URL

Public Class Methods

new() click to toggle source
# File lib/frameio/auth.rb, line 8
def initialize
end

Public Instance Methods

create_auth_token(auth_code:) click to toggle source
# File lib/frameio/auth.rb, line 23
def create_auth_token(auth_code:)
  body = {
    code: auth_code,
    grant_type: "authorization_code",
    redirect_uri: Frameio.configuration.auth_redirect_uri,
  }
  request(body)
end
create_auth_url(state: "default_state") click to toggle source
# File lib/frameio/auth.rb, line 11
def create_auth_url(state: "default_state")
  uri = Addressable::URI.new
  uri.query_values = {
    response_type: 'code',
    redirect_uri: Frameio.configuration.auth_redirect_uri,
    client_id: Frameio.configuration.client_id,
    scope: Frameio.configuration.scope,
    state: state
  }
  "#{AUTH_URL}?#{uri.query}"
end
refresh_auth_token(token) click to toggle source
# File lib/frameio/auth.rb, line 32
def refresh_auth_token(token)
  refresh_token = find_refresh_token(token)
  body = {
    grant_type: "refresh_token",
    refresh_token: refresh_token
  }
  request(body)
end

Private Instance Methods

encoded_secret() click to toggle source
# File lib/frameio/auth.rb, line 43
def encoded_secret
  client_id = Frameio.configuration.client_id
  client_secret = Frameio.configuration.client_secret
  Base64.strict_encode64("#{client_id}:#{client_secret}")
end
find_refresh_token() click to toggle source
# File lib/frameio/auth.rb, line 49
def find_refresh_token
  refresh_token =  @token[:token]&.refresh_token if @token.methods.include? :refresh_token
  refresh_token = @token[:token][:refresh_token] if @token.class.to_s == "Hash"
  return refresh_token
  if refresh_token.empty?
    raise "Please supply a valid frameio token with an refresh_token attribute or method"
  end
end
request(body) click to toggle source
# File lib/frameio/auth.rb, line 58
def request(body)
  HTTParty.send(
    :post,
    "https://applications.frame.io/oauth2/token",
    headers: { Authorization: "Basic #{encoded_secret}" },
    body: body,
  )
end