Created
May 1, 2018 21:59
-
-
Save toreriklinnerud/63e0ee646ef7988c2451ac40fb352963 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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