okta / okta-sdk-php

PHP SDK for the Okta API
Apache License 2.0
38 stars 71 forks source link

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

Open chuckienorton opened 2 years ago

chuckienorton commented 2 years ago

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 commented 2 years ago

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.