okta-sdk-php icon indicating copy to clipboard operation
okta-sdk-php copied to clipboard

assignUserToApplication() InvalidArgumentException with message 'First argument to Stream::create() must be a string, resource or StreamInterface.'

Open chuckienorton opened this issue 3 years ago • 1 comments

I'm having trouble using the application assignUserToApplication method, which requires an AppUser.

Here is my current code:

$oktaAppUser =  new \Okta\Applications\AppUser();
$oktaAppUser->setId($oktaUserId);
$oktaAppUser->setScope("USER");

$oktaApp = $this->getApplication($oktaApplicationId);
$oktaApp->assignUserToApplication($oktaAppUser);

This returns the following error: InvalidArgumentException with message 'First argument to Stream::create() must be a string, resource or StreamInterface.'

Am i initiating this incorrecly? I can retrieve 'read-only' items from $oktaApp like getApplicationUsers, etc.

Thanks in advance! PS - this might be related to https://github.com/okta/okta-sdk-php/issues/133

chuckienorton avatar Feb 18 '22 15:02 chuckienorton

For future readers - i was able to bypass that method and call the api directly through the okta-sdk.

$uri = "/api/v1/apps/{$oktaApplicationId}/users";
$uri = $this->client->getDataStore()->buildUri(
    $this->client->getDataStore()->getOrganizationUrl() . $uri
);
$body = $clientBuilder
    ->getDataStore()
    ->executeRequest('POST', $uri, json_encode(["id" => $oktaUserId]));

Would still love to know how to use the sdk directly.

chuckienorton avatar Feb 18 '22 16:02 chuckienorton