Create user on keycloak with Angular 7 by REST API



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I have a little problem to register a user on Keycloak.



I use keycloak-admin-client:



let keycloakAdminClient = require('keycloak-admin-client');


When the client tries to create a user, the server says 403 forbidden.



keycloakAdminClient(clientSettings)
.then((clients) =>
console.log('[newRegistration - keycloakAdminClient] init success');
console.log(clients.token);
clients.users.create(environment.KEYCLOAK_REALM, newKeycloakUser)
.then((createdUser) =>
console.log('[newRegistration - keycloakAdminClient - client.users.create] success - createdUser = ' + createdUser);
// findNewUserId(newKeycloakUser.username);
return newKeycloakUser.username;
)
.catch((err) =>

console.log('[newRegistration - keycloakAdminClient - client.users.create] error - code = ', err);
);
)
.catch((err) =>
console.log('[newRegistration - keycloakAdminClient] init error - code = ', err);
);
console.log('[newRegistration] END');
};


This is the settings of client:



 export const environment = 
production: false,
KEYCLOAK_URL: 'http://10.10.15.35:8080/auth',
KEYCLOAK_REALM: 'baulogistik_test',
KEYCLOAK_CLIENTID: 'angular-frontend',
BACKEND_URL: 'http://10.10.15.35:8080/api',
CLIENT_SECRET: '296f7a0f-a0f5-4395-a120-ece8565bbce1'
;

const clientSettings =
production: environment.production,
baseUrl: environment.KEYCLOAK_URL,
client_id: environment.KEYCLOAK_CLIENTID,
realmName: environment.KEYCLOAK_REALM,
grant_type: 'client_credentials',
client_secret: environment.CLIENT_SECRET



I can log in with the client via the secret key and get an accessToken.



The client has admin role.



Role Settings on keycloak



client settings



Have anybody an advice for me?
Thanks!










share|improve this question
























  • Hi, welcome to stack overflow. Are you sure the client is the one creating the user and you're not creating the user using your current logged in user's token?

    – Xtreme Biker
    Nov 15 '18 at 14:16











  • Thank you. Yes, I try to create the user by using the client access token.

    – Ha Bardan
    Nov 16 '18 at 7:05











  • Try with some HTTP client like Postman to create it. If it works, you're doing something wrong in the Angular side. If not, it is the KC server being misconfigured.

    – Xtreme Biker
    Nov 16 '18 at 7:18











  • I have the same error with postman. The kc server could be misconfigured.

    – Ha Bardan
    Nov 16 '18 at 9:18

















0















I have a little problem to register a user on Keycloak.



I use keycloak-admin-client:



let keycloakAdminClient = require('keycloak-admin-client');


When the client tries to create a user, the server says 403 forbidden.



keycloakAdminClient(clientSettings)
.then((clients) =>
console.log('[newRegistration - keycloakAdminClient] init success');
console.log(clients.token);
clients.users.create(environment.KEYCLOAK_REALM, newKeycloakUser)
.then((createdUser) =>
console.log('[newRegistration - keycloakAdminClient - client.users.create] success - createdUser = ' + createdUser);
// findNewUserId(newKeycloakUser.username);
return newKeycloakUser.username;
)
.catch((err) =>

console.log('[newRegistration - keycloakAdminClient - client.users.create] error - code = ', err);
);
)
.catch((err) =>
console.log('[newRegistration - keycloakAdminClient] init error - code = ', err);
);
console.log('[newRegistration] END');
};


This is the settings of client:



 export const environment = 
production: false,
KEYCLOAK_URL: 'http://10.10.15.35:8080/auth',
KEYCLOAK_REALM: 'baulogistik_test',
KEYCLOAK_CLIENTID: 'angular-frontend',
BACKEND_URL: 'http://10.10.15.35:8080/api',
CLIENT_SECRET: '296f7a0f-a0f5-4395-a120-ece8565bbce1'
;

const clientSettings =
production: environment.production,
baseUrl: environment.KEYCLOAK_URL,
client_id: environment.KEYCLOAK_CLIENTID,
realmName: environment.KEYCLOAK_REALM,
grant_type: 'client_credentials',
client_secret: environment.CLIENT_SECRET



I can log in with the client via the secret key and get an accessToken.



The client has admin role.



Role Settings on keycloak



client settings



Have anybody an advice for me?
Thanks!










share|improve this question
























  • Hi, welcome to stack overflow. Are you sure the client is the one creating the user and you're not creating the user using your current logged in user's token?

    – Xtreme Biker
    Nov 15 '18 at 14:16











  • Thank you. Yes, I try to create the user by using the client access token.

    – Ha Bardan
    Nov 16 '18 at 7:05











  • Try with some HTTP client like Postman to create it. If it works, you're doing something wrong in the Angular side. If not, it is the KC server being misconfigured.

    – Xtreme Biker
    Nov 16 '18 at 7:18











  • I have the same error with postman. The kc server could be misconfigured.

    – Ha Bardan
    Nov 16 '18 at 9:18













0












0








0








I have a little problem to register a user on Keycloak.



I use keycloak-admin-client:



let keycloakAdminClient = require('keycloak-admin-client');


When the client tries to create a user, the server says 403 forbidden.



keycloakAdminClient(clientSettings)
.then((clients) =>
console.log('[newRegistration - keycloakAdminClient] init success');
console.log(clients.token);
clients.users.create(environment.KEYCLOAK_REALM, newKeycloakUser)
.then((createdUser) =>
console.log('[newRegistration - keycloakAdminClient - client.users.create] success - createdUser = ' + createdUser);
// findNewUserId(newKeycloakUser.username);
return newKeycloakUser.username;
)
.catch((err) =>

console.log('[newRegistration - keycloakAdminClient - client.users.create] error - code = ', err);
);
)
.catch((err) =>
console.log('[newRegistration - keycloakAdminClient] init error - code = ', err);
);
console.log('[newRegistration] END');
};


This is the settings of client:



 export const environment = 
production: false,
KEYCLOAK_URL: 'http://10.10.15.35:8080/auth',
KEYCLOAK_REALM: 'baulogistik_test',
KEYCLOAK_CLIENTID: 'angular-frontend',
BACKEND_URL: 'http://10.10.15.35:8080/api',
CLIENT_SECRET: '296f7a0f-a0f5-4395-a120-ece8565bbce1'
;

const clientSettings =
production: environment.production,
baseUrl: environment.KEYCLOAK_URL,
client_id: environment.KEYCLOAK_CLIENTID,
realmName: environment.KEYCLOAK_REALM,
grant_type: 'client_credentials',
client_secret: environment.CLIENT_SECRET



I can log in with the client via the secret key and get an accessToken.



The client has admin role.



Role Settings on keycloak



client settings



Have anybody an advice for me?
Thanks!










share|improve this question
















I have a little problem to register a user on Keycloak.



I use keycloak-admin-client:



let keycloakAdminClient = require('keycloak-admin-client');


When the client tries to create a user, the server says 403 forbidden.



keycloakAdminClient(clientSettings)
.then((clients) =>
console.log('[newRegistration - keycloakAdminClient] init success');
console.log(clients.token);
clients.users.create(environment.KEYCLOAK_REALM, newKeycloakUser)
.then((createdUser) =>
console.log('[newRegistration - keycloakAdminClient - client.users.create] success - createdUser = ' + createdUser);
// findNewUserId(newKeycloakUser.username);
return newKeycloakUser.username;
)
.catch((err) =>

console.log('[newRegistration - keycloakAdminClient - client.users.create] error - code = ', err);
);
)
.catch((err) =>
console.log('[newRegistration - keycloakAdminClient] init error - code = ', err);
);
console.log('[newRegistration] END');
};


This is the settings of client:



 export const environment = 
production: false,
KEYCLOAK_URL: 'http://10.10.15.35:8080/auth',
KEYCLOAK_REALM: 'baulogistik_test',
KEYCLOAK_CLIENTID: 'angular-frontend',
BACKEND_URL: 'http://10.10.15.35:8080/api',
CLIENT_SECRET: '296f7a0f-a0f5-4395-a120-ece8565bbce1'
;

const clientSettings =
production: environment.production,
baseUrl: environment.KEYCLOAK_URL,
client_id: environment.KEYCLOAK_CLIENTID,
realmName: environment.KEYCLOAK_REALM,
grant_type: 'client_credentials',
client_secret: environment.CLIENT_SECRET



I can log in with the client via the secret key and get an accessToken.



The client has admin role.



Role Settings on keycloak



client settings



Have anybody an advice for me?
Thanks!







angular keycloak angular7






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 18 '18 at 15:45









Goncalo Peres

1,4771721




1,4771721










asked Nov 15 '18 at 11:21









Ha BardanHa Bardan

154




154












  • Hi, welcome to stack overflow. Are you sure the client is the one creating the user and you're not creating the user using your current logged in user's token?

    – Xtreme Biker
    Nov 15 '18 at 14:16











  • Thank you. Yes, I try to create the user by using the client access token.

    – Ha Bardan
    Nov 16 '18 at 7:05











  • Try with some HTTP client like Postman to create it. If it works, you're doing something wrong in the Angular side. If not, it is the KC server being misconfigured.

    – Xtreme Biker
    Nov 16 '18 at 7:18











  • I have the same error with postman. The kc server could be misconfigured.

    – Ha Bardan
    Nov 16 '18 at 9:18

















  • Hi, welcome to stack overflow. Are you sure the client is the one creating the user and you're not creating the user using your current logged in user's token?

    – Xtreme Biker
    Nov 15 '18 at 14:16











  • Thank you. Yes, I try to create the user by using the client access token.

    – Ha Bardan
    Nov 16 '18 at 7:05











  • Try with some HTTP client like Postman to create it. If it works, you're doing something wrong in the Angular side. If not, it is the KC server being misconfigured.

    – Xtreme Biker
    Nov 16 '18 at 7:18











  • I have the same error with postman. The kc server could be misconfigured.

    – Ha Bardan
    Nov 16 '18 at 9:18
















Hi, welcome to stack overflow. Are you sure the client is the one creating the user and you're not creating the user using your current logged in user's token?

– Xtreme Biker
Nov 15 '18 at 14:16





Hi, welcome to stack overflow. Are you sure the client is the one creating the user and you're not creating the user using your current logged in user's token?

– Xtreme Biker
Nov 15 '18 at 14:16













Thank you. Yes, I try to create the user by using the client access token.

– Ha Bardan
Nov 16 '18 at 7:05





Thank you. Yes, I try to create the user by using the client access token.

– Ha Bardan
Nov 16 '18 at 7:05













Try with some HTTP client like Postman to create it. If it works, you're doing something wrong in the Angular side. If not, it is the KC server being misconfigured.

– Xtreme Biker
Nov 16 '18 at 7:18





Try with some HTTP client like Postman to create it. If it works, you're doing something wrong in the Angular side. If not, it is the KC server being misconfigured.

– Xtreme Biker
Nov 16 '18 at 7:18













I have the same error with postman. The kc server could be misconfigured.

– Ha Bardan
Nov 16 '18 at 9:18





I have the same error with postman. The kc server could be misconfigured.

– Ha Bardan
Nov 16 '18 at 9:18












1 Answer
1






active

oldest

votes


















0














I got it.
You have to add the roles from the realm-management client to your admin role.



Resolve



After that, a user must have the admin role.
Then the clientSettings has to be extended in the Angular app:



  • Add username and password of your admin user


  • Modify grant_type to password



    const clientSettings = {
    production: environment.production,
    baseUrl: environment.KEYCLOAK_URL,
    client_id: environment.KEYCLOAK_CLIENTID,
    realmName: environment.KEYCLOAK_REALM,
    grant_type: 'password',//'client_credentials',
    username: environment.username,
    password: environment.password,
    client_secret: environment.CLIENT_SECRET






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53318363%2fcreate-user-on-keycloak-with-angular-7-by-rest-api%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    I got it.
    You have to add the roles from the realm-management client to your admin role.



    Resolve



    After that, a user must have the admin role.
    Then the clientSettings has to be extended in the Angular app:



    • Add username and password of your admin user


    • Modify grant_type to password



      const clientSettings = {
      production: environment.production,
      baseUrl: environment.KEYCLOAK_URL,
      client_id: environment.KEYCLOAK_CLIENTID,
      realmName: environment.KEYCLOAK_REALM,
      grant_type: 'password',//'client_credentials',
      username: environment.username,
      password: environment.password,
      client_secret: environment.CLIENT_SECRET






    share|improve this answer



























      0














      I got it.
      You have to add the roles from the realm-management client to your admin role.



      Resolve



      After that, a user must have the admin role.
      Then the clientSettings has to be extended in the Angular app:



      • Add username and password of your admin user


      • Modify grant_type to password



        const clientSettings = {
        production: environment.production,
        baseUrl: environment.KEYCLOAK_URL,
        client_id: environment.KEYCLOAK_CLIENTID,
        realmName: environment.KEYCLOAK_REALM,
        grant_type: 'password',//'client_credentials',
        username: environment.username,
        password: environment.password,
        client_secret: environment.CLIENT_SECRET






      share|improve this answer

























        0












        0








        0







        I got it.
        You have to add the roles from the realm-management client to your admin role.



        Resolve



        After that, a user must have the admin role.
        Then the clientSettings has to be extended in the Angular app:



        • Add username and password of your admin user


        • Modify grant_type to password



          const clientSettings = {
          production: environment.production,
          baseUrl: environment.KEYCLOAK_URL,
          client_id: environment.KEYCLOAK_CLIENTID,
          realmName: environment.KEYCLOAK_REALM,
          grant_type: 'password',//'client_credentials',
          username: environment.username,
          password: environment.password,
          client_secret: environment.CLIENT_SECRET






        share|improve this answer













        I got it.
        You have to add the roles from the realm-management client to your admin role.



        Resolve



        After that, a user must have the admin role.
        Then the clientSettings has to be extended in the Angular app:



        • Add username and password of your admin user


        • Modify grant_type to password



          const clientSettings = {
          production: environment.production,
          baseUrl: environment.KEYCLOAK_URL,
          client_id: environment.KEYCLOAK_CLIENTID,
          realmName: environment.KEYCLOAK_REALM,
          grant_type: 'password',//'client_credentials',
          username: environment.username,
          password: environment.password,
          client_secret: environment.CLIENT_SECRET







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 19 '18 at 7:21









        Ha BardanHa Bardan

        154




        154





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53318363%2fcreate-user-on-keycloak-with-angular-7-by-rest-api%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Use pre created SQLite database for Android project in kotlin

            Darth Vader #20

            Ondo