Class: KeycloakAdmin::IdentityProviderClient

Inherits:
Client
  • Object
show all
Defined in:
lib/keycloak-admin/client/identity_provider_client.rb

Instance Method Summary collapse

Methods inherited from Client

#create_payload, #created_id, #current_token, #execute_http, #headers, #server_url

Constructor Details

#initialize(configuration, realm_client) ⇒ IdentityProviderClient

Returns a new instance of IdentityProviderClient.

Raises:

  • (ArgumentError)


3
4
5
6
7
# File 'lib/keycloak-admin/client/identity_provider_client.rb', line 3

def initialize(configuration, realm_client)
  super(configuration)
  raise ArgumentError.new("realm must be defined") unless realm_client.name_defined?
  @realm_client = realm_client
end

Instance Method Details

#add_mapping(identity_provider_alias, identity_provider_mapping_representation) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/keycloak-admin/client/identity_provider_client.rb', line 17

def add_mapping(identity_provider_alias, identity_provider_mapping_representation)
  execute_http do
    RestClient::Resource.new(identity_provider_mappers_url(identity_provider_alias), @configuration.rest_client_options).post(
      create_payload(identity_provider_mapping_representation), headers
    )
  end
end

#create(identity_provider_representation) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/keycloak-admin/client/identity_provider_client.rb', line 9

def create(identity_provider_representation)
  execute_http do
    RestClient::Resource.new(identity_providers_url, @configuration.rest_client_options).post(
      create_payload(identity_provider_representation), headers
    )
  end
end

#get(internal_id_or_alias = nil) ⇒ Object



32
33
34
35
36
37
# File 'lib/keycloak-admin/client/identity_provider_client.rb', line 32

def get(internal_id_or_alias=nil)
  response = execute_http do
    RestClient::Resource.new(identity_providers_url(internal_id_or_alias), @configuration.rest_client_options).get(headers)
  end
  IdentityProviderRepresentation.from_hash(JSON.parse(response))
end

#identity_provider_mappers_url(internal_id_or_alias) ⇒ Object



47
48
49
# File 'lib/keycloak-admin/client/identity_provider_client.rb', line 47

def identity_provider_mappers_url(internal_id_or_alias)
  "#{identity_providers_url(internal_id_or_alias)}/mappers"
end

#identity_providers_url(internal_id_or_alias = nil) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/keycloak-admin/client/identity_provider_client.rb', line 39

def identity_providers_url(internal_id_or_alias=nil)
  if internal_id_or_alias
    "#{@realm_client.realm_admin_url}/identity-provider/instances/#{internal_id_or_alias}"
  else
    "#{@realm_client.realm_admin_url}/identity-provider/instances"
  end
end

#listObject



25
26
27
28
29
30
# File 'lib/keycloak-admin/client/identity_provider_client.rb', line 25

def list
  response = execute_http do
    RestClient::Resource.new(identity_providers_url, @configuration.rest_client_options).get(headers)
  end
  JSON.parse(response).map { |provider_as_hash| IdentityProviderRepresentation.from_hash(provider_as_hash) }
end