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

graph::CreateUser - Unable to specify correct UserCreationContext #33

Closed
tiwood opened this issue Oct 18, 2019 · 5 comments
Closed

graph::CreateUser - Unable to specify correct UserCreationContext #33

tiwood opened this issue Oct 18, 2019 · 5 comments
Labels
bug Something isn't working

Comments

@tiwood
Copy link

tiwood commented Oct 18, 2019

To create a user with graph.CreateUser we have to provide CreateUserArgs:

// Arguments for the CreateUser function
type CreateUserArgs struct {
	// (required) The subset of the full graph user used to uniquely find the graph subject in an external provider.
	CreationContext *GraphUserCreationContext
	// (optional) A comma separated list of descriptors of groups you want the graph user to join
	GroupDescriptors *[]string
}

The CreationContext decides if we create an aad, ad or msa account, but the current implementation only allows us to use the following context (which shouldn't be used):

// Do not attempt to use this type to create a new user. Use one of the subclasses instead. This type does not contain sufficient fields to create a new user.
type GraphUserCreationContext struct {
	// Optional: If provided, we will use this identifier for the storage key of the created user
	StorageKey *uuid.UUID `json:"storageKey,omitempty"`
}

Instead we should be able to provide one of the following:

type GraphUserPrincipalNameCreationContext struct {
	// Optional: If provided, we will use this identifier for the storage key of the created user
	StorageKey *uuid.UUID `json:"storageKey,omitempty"`
	// This should be the principal name or upn of the user in the source AD or AAD provider. Example: jamal@contoso.com Team Services will communicate with the source provider to fill all other fields on creation.
	PrincipalName *string `json:"principalName,omitempty"`
}

type GraphUserMailAddressCreationContext struct {
	// Optional: If provided, we will use this identifier for the storage key of the created user
	StorageKey  *uuid.UUID `json:"storageKey,omitempty"`
	MailAddress *string    `json:"mailAddress,omitempty"`
}
@tedchamb tedchamb self-assigned this Oct 19, 2019
@tedchamb tedchamb added the bug Something isn't working label Oct 19, 2019
@tedchamb
Copy link
Member

Thanks @tiwood , this is an issue where Go's lack of inheritance makes this difficult to address in the code generator. This is going to affect any method that accepts different subclasses as input. Fortunately there are not a lot of methods that fall into this category. I have a plan on how to fix this, but not sure when I will be able to get to it. Can you give me an idea of the priority of this particular issue for your application?

Thanks,
Ted

@tedchamb
Copy link
Member

The GraphClient is meant to replace the IdentityClient, but the IdentityClient still works. Until this issue is fixed, you may want to try the CreateIdentity method on the IdentityClient.

@tmeckel
Copy link
Contributor

tmeckel commented Oct 21, 2019

@tedchamb is it possible to change the signature of the CreateUser method as follows (making parameter args generic)?

func (client *ClientImpl) CreateUser(ctx context.Context, args interface{}) (*GraphUser, error) {

and then checking in the method body for valid struct types?

tmeckel added a commit to tiwood/terraform-provider-azuredevops that referenced this issue Dec 5, 2019
@tmeckel
Copy link
Contributor

tmeckel commented Dec 6, 2019

The GraphClient is meant to replace the IdentityClient, but the IdentityClient still works. Until this issue is fixed, you may want to try the CreateIdentity method on the IdentityClient.

@tedchamb as we have the same issue with creating Groups via the Graph API I wanted to use the CreateGroups function from the Indentity API. The following structure must be passed as argument to CreateGroups

// Arguments for the CreateGroups function
type CreateGroupsArgs struct {
	// (required)
	Container interface{}
}

But because an interface{} is used as type for the Container struct element and there's no further description on this, I'm unable to use the CreateGroups method.

tmeckel added a commit to tiwood/terraform-provider-azuredevops that referenced this issue Dec 7, 2019
@tedchamb tedchamb removed their assignment Jun 30, 2021
@nechvatalp
Copy link
Collaborator

I attempted to fix this in the latest 7.1 release by providing by providing more variants of the methods each accepting different context.

I added such "overloads" for both Users and Groups, I was able to call create user successfully with that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants