Open albanafmeti opened 7 years ago
Thanks for collaborating @albanafmeti !
I chose to encapsulate a maximum of the login logic inside the API objects, so that it's straightforward to use it. Concerning the Auth Token, I save it when the login
method is called with $save_auth=true
:
if( $save_auth) {
// save auth token for future requests
$tmp = Request::init()
->addHeader('X-Auth-Token', $response->body->data->authToken)
->addHeader('X-User-Id', $response->body->data->userId);
Request::ini( $tmp );
}
Doing this will ship the auth token automatically with following requests, so you don't have to worry about it.
If you need the auth token outside the login method, you can get it from the Request :
$token = Request::init()->headers["X-Auth-Token"];
Check this out https://github.com/albanafmeti/rocket-chat
Why returning
true
when somebody may need more information for exampleauthToken
? The returned object is different fromfalse
so I think it will be fine returning the object$response->body->data
.