class Knock::Oauth2CodeVerifier::AuthTokenController

Public Instance Methods

create() click to toggle source
# File app/controllers/knock/oauth2_code_verifier/auth_token_controller.rb, line 13
def create
  raise "Implement #create in your controller"
end

Private Instance Methods

access_token() click to toggle source
# File app/controllers/knock/oauth2_code_verifier/auth_token_controller.rb, line 33
def access_token
  @access_token ||= client
    .auth_code
    .get_token(
      params[:code],
      {
        redirect_uri: params[:redirect_uri],
        code_verifier: params[:code_verifier],
      },
    )
end
client() click to toggle source
# File app/controllers/knock/oauth2_code_verifier/auth_token_controller.rb, line 23
def client
  @client ||= OAuth2::Client.new(
    config.client_id,
    config.client_secret,
    authorize_url: config.authorize_url,
    token_url: config.token_url,
    logger: Rails.logger,
  )
end
config() click to toggle source
# File app/controllers/knock/oauth2_code_verifier/auth_token_controller.rb, line 19
def config
  Knock::Oauth2CodeVerifier.configuration.for_provider(params[:provider])
end
refresh_token() click to toggle source
# File app/controllers/knock/oauth2_code_verifier/auth_token_controller.rb, line 45
def refresh_token
  # Only set on the first auth, and perhaps if the access token expires?
  # e.g. https://developers.google.com/identity/protocols/oauth2#expiration
  access_token&.refresh_token
end
user_info() click to toggle source
# File app/controllers/knock/oauth2_code_verifier/auth_token_controller.rb, line 51
def user_info
  return @user_info if @user_info

  info = JSON.parse(access_token.get(config[:userinfo_url]).body)

  @user_info = {
    auth_provider: params[:provider],
    name: info["name"] || info["displayName"],
    email: info["email"] || info["mail"],
    refresh_token: refresh_token,
    raw_info: info,
  }
end