I have also written a small JAVA client to import JSON and I get same 415
error through that also. Here's Java client code:
*File realmConfigFile = new File("D:\\test\\realm.json");*
*if(!realmConfigFile.exists() || realmConfigFile.isDirectory()) { *
* // return failure*
*}*
*String urlString = "http://localhost:8380/auth
<
http://localhost:8380/auth>";*
*URL url = null;*
*InputStream stream = null;*
*HttpURLConnection urlConnection = null;*
*String result = "";*
*try {*
* KeycloakSecurityContext keycloakSecurityContext =
(KeycloakSecurityContext)
request.getAttribute(KeycloakSecurityContext.class.getName()); *
* String token = keycloakSecurityContext.getTokenString();*
* if(StringUtils.isBlank(token))*
* return Response.status(Response.Status.UNAUTHORIZED).build();*
* url = new URL(urlString);*
* urlConnection = (HttpURLConnection) url.openConnection();*
* urlConnection.setRequestMethod("POST");*
* urlConnection.setDoOutput(true);*
* urlConnection.setRequestProperty ("Authorization", "Bearer
"+token);*
* urlConnection.setRequestProperty("Content-Type", "application/json;
charset=UTF-8");*
* urlConnection.connect();*
* String realmJson = FileUtils.readFileToString(realmConfigFile, "UTF-8");*
* OutputStreamWriter wr = new
OutputStreamWriter(urlConnection.getOutputStream());*
* wr.write(realmJson);*
* wr.flush();*
* stream = urlConnection.getInputStream();*
* BufferedReader reader = new BufferedReader(new InputStreamReader(stream,
"UTF-8"), 8);*
* result = reader.readLine(); *
* return Response.ok("request complted").build();*
*} catch (Exception e){*
*}*
On Mon, Oct 22, 2018 at 11:09 AM Bruce Wings <testoauth55(a)gmail.com> wrote:
Forgot to mention that sending request to:
*http://localhost:8380/auth
<
http://localhost:8380/auth/admin/realms>* gives 415-Unsupported media
type error. Images for postman request attached
On Mon, Oct 22, 2018 at 10:16 AM Bruce Wings <testoauth55(a)gmail.com>
wrote:
> As mentioned in docs:
>
https://www.keycloak.org/docs-api/4.5/rest-api/index.html#_realms_admin_r...
> when I send a request to : *http://localhost:8380/
> <
http://localhost:8380/>* I get 200 OK, but when I go and check on
> the admin console, new realm is not visible.
>
> *but when* I send a request to : *http://localhost:8380/auth/admin/realms
> <
http://localhost:8380/auth/admin/realms>, *I get 401 unauthorized.
> (keycloak server running on port 8380 and I am sending the bearer token
> obtained from
>
http://10.252.70.71:8380/auth/realms/master/protocol/openid-connect/token
> )
>
> Which is the accurate URL to import a realm json in keycloak?
*http://localhost:8380/
> <
http://localhost:8380/>* OR *http://localhost:8380/auth/admin/realms
> <
http://localhost:8380/auth/admin/realms>*
>
>
> On Fri, Oct 19, 2018 at 7:43 PM Bruce Wings <testoauth55(a)gmail.com>
> wrote:
>
>> Can anyone suggest whether there is something wrong in the way I am
>> sending request or is this an issue on keycloak side?
>>
>> On Thursday, October 18, 2018, Bruce Wings <testoauth55(a)gmail.com>
>> wrote:
>>
>>> As mentioned in docs:
>>>
>>>
>>>
https://www.keycloak.org/docs-api/4.4/rest-api/index.html#_realms_admin_r...
>>>
>>> I have created a post request via postman and the response is 200 OK,
>>> but when I go and check on the admin console, new realm is not visible.
>>>
>>> Moreover, when I perform the same operation via an invalid token, then
>>> also the response is 200 OK. Am I missing something here?
>>>
>>> Attached screenshot of postman request. (In the body I have copy pasted
>>> entire contents of realm json file that was exported from another server)
>>>
>>>