Assigning role while user registration

When a user registers with my application via Keycloak I want to assign a
particular role depending on the way they have registered (to be
determined). Can anyone point me to an example?