class OmniAuth::Strategies::Oidc

OIDC strategy for omniauth

def authorization_code

def authorization_code
  params["code"]
end

def client

Initialize Oidc Client with options
def client
  @client ||= ::Oidc::Client.new(client_options)
end

def client_options

def client_options
  options.client_options
end

def config

Config is build from the json response from the OIDC config endpoint
def config
  unless client_options.config_endpoint || params["config_endpoint"]
    raise Error,
          "Configuration endpoint is missing from options"
  end
  @config ||= OpenidConfigParser.fetch_openid_configuration(client_options.config_endpoint)
end

def encoded_post_logout_redirect_uri

def encoded_post_logout_redirect_uri
  return unless options.post_logout_redirect_uri
  URI.encode_www_form(
    post_logout_redirect_uri: options.post_logout_redirect_uri
  )
end

def end_session_endpoint_is_valid?

def end_session_endpoint_is_valid?
  client_options.end_session_endpoint &&
    client_options.end_session_endpoint =~ URI::DEFAULT_PARSER.make_regexp
end

def end_session_uri

def end_session_uri
  return unless end_session_endpoint_is_valid?
  end_session_uri = URI(client_options.end_session_endpoint)
  end_session_uri.query = encoded_post_logout_redirect_uri
  end_session_uri.to_s
end

def host

def host
  @host ||= URI.parse(config.issuer).host
end

def issuer

def issuer
  @issuer ||= config.issuer
end

def logout_path_pattern

def logout_path_pattern
  @logout_path_pattern ||= /\A#{Regexp.quote(request_path)}#{options.logout_path}/
end

def new_nonce

def new_nonce
  session["omniauth.nonce"] = SecureRandom.hex(16)
end

def other_phase

def other_phase
  if logout_path_pattern.match?(current_path)
    options.issuer = issuer if options.issuer.to_s.empty?
    return redirect(end_session_uri) if end_session_uri
  end
  call_app!
end

def redirect_uri

def redirect_uri
  "#{request.base_url}/auth/#{name}/callback"
end

def resolve_endpoint_from_host(host, endpoint)

Strips port and host from strings with OIDC endpoints
def resolve_endpoint_from_host(host, endpoint)
  start_index = endpoint.index(host) + host.length
  endpoint = endpoint[start_index..]
  endpoint = "/#{endpoint}" unless endpoint.start_with?("/")
  endpoint
end

def scope

By default Returns all scopes supported by the OIDC provider
def scope
  config.scopes_supported || options.scope
end

def script_name

def script_name
  return "" if @env.nil?
  super
end

def session

def session
  return {} if @env.nil?
  super
end

def stored_state

def stored_state
  session.delete("omniauth.state")
end

def uid

def uid
  user_info.raw_attributes[options.uid_field.to_sym] || user_info.sub
end