Skip to content

Instantly share code, notes, and snippets.

@toreriklinnerud
Created May 1, 2018 21:59
Show Gist options
  • Save toreriklinnerud/63e0ee646ef7988c2451ac40fb352963 to your computer and use it in GitHub Desktop.
Save toreriklinnerud/63e0ee646ef7988c2451ac40fb352963 to your computer and use it in GitHub Desktop.
class Auth0Token
def request_token
connection = Faraday.new(url: "https://rubyfriend.auth0.com/oauth/token")
response = connection.post do |request|
request.headers['Content-Type'] = 'application/json'
request.body = payload.to_json
end
JSON.parse(response.body)
end
def send_email(uid)
connection = Faraday.new(url: "https://" + ENV.fetch('AUTH0_DOMAIN') + "/api/v2/jobs/verification-email")
response = connection.post do |request|
request.headers['Content-Type'] = 'application/json'
request.headers['Authorization'] = "Bearer #{request_token.fetch("access_token")}"
request.body = {"user_id" => uid}.to_json
puts request.headers
end
response.body
end
def payload
{
"grant_type" => "client_credentials",
"client_id" => ENV.fetch('AUTH0_CLIENT_ID'),
"client_secret" => ENV.fetch('AUTH0_CLIENT_SECRET'),
"audience" => "https://" + ENV.fetch('AUTH0_DOMAIN') + "/api/v2/"
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment