Error obtaining userToken for JWT authorized app with .NET SDK
In my JWT authenticated app, I need the capability to create a user, and immediately upload content to this user's account. While attempting to get a userToken for the newly created user, I get the error:
System.NullReferenceException: Object reference not set to an instance of an object.
Here is a code sample:
//authorize jwt and get admin token
StreamReader reader = new StreamReader(Config.BoxCredentialsFile);
string json = reader.ReadToEnd();
IBoxConfig config = BoxConfig.CreateFromJsonString(json);
SDK = new BoxJWTAuth(config);
string token = SDK.AdminToken();
BoxClient adminClient = SDK.AdminClient(token);
//create new user
var userRequest = new BoxUserRequest()
{
Login = "***email address removed for privacy***",
Name = Person,
};
BoxUser user = adminClient.UsersManager.CreateEnterpriseUserAsync(userRequest).Result;
//get user token
string userToken = SDK.UserToken(user.Id); //this is the line that causes the error
userClient = SDK.UserClient(userToken, user.Id);
I don't understand why I'm getting a NullReferenceException. The user is created successfully (confirmed through the admin console), and I can access the attributes of user without issue (including user.Id). Additionally, I have no problem getting a userToken for users who are currently active or are created through the admin console, the issue only occurs for users created through the API.
Has anyone else encountered this issue before?
-
After some more testing it looks like you can't request a userToken in this way until the user has logged in themselves through their activation email. I'm also unable to login as a newly created user through the admin console, so I don't think this is specific to the .NET SDK. If anybody has a workaround I would appreciate the help, otherwise our company may need to rethink our requirements about this application.
Please sign in to leave a comment.
Comments
1 comment