Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

username in user registration is no use when registering a user #25

Closed
hantsy opened this issue Mar 16, 2022 · 6 comments
Closed

username in user registration is no use when registering a user #25

hantsy opened this issue Mar 16, 2022 · 6 comments

Comments

@hantsy
Copy link

hantsy commented Mar 16, 2022

I was trying to use register to add a new user.

        val request = RegistrationRequest(
            User().apply {
                firstName = data.firstName
                lastName = data.lastName
                email = data.email
                mobilePhone = data.phoneNumber
                password = randomAlphanumericString(8)
                username = data.firstName.lowercase() + "_" + randomAlphanumericString(6)
            },
            UserRegistration().apply {
                roles =sortedSetOf<String>("ADMIN")
                applicationId = mapplicationId
                // if set here, username is not stored.
                // username = data.firstName.lowercase() + "_" + randomAlphanumericString(6)
            }
        )
            client.register(UUID.randomUUID(), request)

If I put the username in the UserRegistration, the result will not contain the username. I have to put it into the User object.

Here register will affect the getRolesOfApplication.

I really do not understand the APIs provided in the Java Client. I can not imagine a request object contains so many fields, but most of them are no use.

@mooreds
Copy link
Contributor

mooreds commented Mar 16, 2022

Hi @hantsy . Thanks for using FusionAuth!

The username in the registration is for display purposes only. From the [registrations documentation[(https://fusionauth.io/docs/v1/tech/apis/registrations), registration.username.

The username of the User for this Application. This username cannot be used to login. It is for display purposes only. The user.username field may be used to login.

So this field lets you have users with different display names in different applications (mooreds in a forum, dan.moore in a support ticket system, etc).

Hope that clears this up. I'm going to close out this issue.

@mooreds mooreds closed this as completed Mar 16, 2022
@hantsy
Copy link
Author

hantsy commented Mar 17, 2022

Currently I used username of UserRegistratoin and call the client register method to register a new user. Not for display.

What confused me it the user registration request spec contains this field, and I have set it, but it is not applied when calling register.

@hantsy
Copy link
Author

hantsy commented Mar 17, 2022

So this field lets you have users with different display names in different applications (mooreds in a forum, dan.moore in a support ticket system, etc).

Currently these fields are part of the request object spec, and they can be set freely, but did not work as expected.

For each endpoints, every field of the request object should be affected if assigning a value.

@mooreds
Copy link
Contributor

mooreds commented Mar 31, 2022

For each endpoints, every field of the request object should be affected if assigning a value.

I'm not sure I understand the issue. Can you please share some code snippets?

@mooreds mooreds reopened this Mar 31, 2022
@mooreds
Copy link
Contributor

mooreds commented Mar 31, 2022

I see some code snippets above, but I'm not clear on which username is not stored if you uncomment username in UserRegistration. Is there a value on user.username, user.registration.username, both or none?

@mooreds
Copy link
Contributor

mooreds commented May 2, 2022

So I just tried to replicate with this code:

package io.fusionauth.example;

import java.util.UUID;
import com.inversoft.error.Errors;
import io.fusionauth.client.FusionAuthClient;
import io.fusionauth.domain.User;
import io.fusionauth.domain.UserRegistration;
import io.fusionauth.domain.api.user.RegistrationRequest;
import io.fusionauth.domain.api.user.RegistrationResponse;
import com.inversoft.rest.ClientResponse;
import java.util.*;

public class RegisterUser {

    public static void main(String[] args) {

        ApplicationProperties.setupProperties();

        // Initiating the client
        FusionAuthClient client = new FusionAuthClient(ApplicationProperties.getApiKey(),
                ApplicationProperties.getFusionAuthURL());

        // Initiating the user and providing registration details
        User javauser = new User();
        javauser.email = "test3@example.com";
        javauser.password = "password";
        javauser.lastName = "last";
        javauser.firstName = "first";
        javauser.username = "username3";

        // Initiating user registration and creating request object
        UserRegistration userreg = new UserRegistration();
        userreg.applicationId = UUID.fromString("20ce6dac-b985-4c77-bb59-6369249f884b");
        SortedSet<String> roles = new TreeSet<String>();
        roles.add("ADMIN");
        userreg.roles = roles;
        userreg.username = "regusername3";

        RegistrationRequest request = new RegistrationRequest(javauser, userreg);

        // Using the returned ClientResponse object
        ClientResponse<RegistrationResponse, Errors> response = client.register(null, request);

        if (response.wasSuccessful()) {
            System.out.println("Registration successful");

        } else {
            // Handling errors
            System.out.println(response.errorResponse);
        }
    }

}

And I was able to provide the username on the user object as well as on the registration object.

I'm going to close this since I can't reproduce. Please re-open if you can provide replication steps or if I misunderstand the issue.

@mooreds mooreds closed this as completed May 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants