v-ladynev / keycloak-nodejs-example

A simply step by step Keycloak, MySQL and Node.js integration tutorial. There are some docker examples as well.
292 stars 101 forks source link

Return custom attributes to client? #5

Closed thebetterjort closed 3 years ago

thebetterjort commented 6 years ago

@v-ladynev Thanks for this repo, its very appreciated.

I'm trying to return some custom attributes that I have created for each user to the client. It's unclear to me how to do this. Do you know how I can return this data?

v-ladynev commented 6 years ago

@thebetterjort You can use as example this method from adminClient.js. User's attributes are stored in the user.attributes field.

    removeTestUserCustomerId() {
        return adminClient(this.config)
            .then(
                client => this.findTestUser()
                    .then(
                        user => {
                            user.attributes = user.attributes || {};
                            user.attributes.customerId = undefined;
                            return client.users.update(this.config.realm, user)
                                .then(() => 'customerId removed');
                        }
                    )
            );
    }

You can get a custom attribute from the ID token as described https://github.com/v-ladynev/keycloak-nodejs-example#add-custom-attribute

v-ladynev commented 3 years ago

It was a question.