Skip to content

Commit

Permalink
logout; close #54
Browse files Browse the repository at this point in the history
  • Loading branch information
justincy committed Nov 5, 2015
1 parent b3efab0 commit 42a581a
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/Rs/Client/GedcomxApplicationState.php
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,26 @@ public function authenticateViaOAuth2WithoutCredentials($ipAddress, $clientId)

return $this->authenticateViaOAuth2($formData);
}

/**
* Invalidate the current access token and end the session.
*
* @return GedcomxApplicationState $this
*/
public function logout()
{
$link = $this->getLink('logout');
if ($link === null || $link->getHref() === null) {
return null;
}

$request = $this->createRequest('GET', $link->getHref() . '?access_token=' . $this->accessToken);
$response = $this->invoke($request);

$this->accessToken = null;

return $this;
}

/**
* Builds a pretty failure message from the specified response's warning headers, using the specified request for
Expand Down
14 changes: 14 additions & 0 deletions tests/Functional/AuthenticationTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,20 @@ public function testBadAuthenticationRequest()
$factory->newCollectionState()
->authenticateViaOAuth2WithoutCredentials('0.0.0.0', 'ABCD-1234-EFGH-5678-IJKL-9012-MNOP');
}

/**
* @vcr Authentication/testLogout.json
*
*/
public function testLogout()
{
$factory = new StateFactory();
$state = $this->collectionState($factory);
$this->authorize($state);
$this->assertNotEmpty($state->getAccessToken());
$state->logout();
$this->assertEmpty($state->getAccessToken());
}

/**
* testObtainAccessTokenWithAuthorizationCode
Expand Down
109 changes: 109 additions & 0 deletions tests/fixtures/Authentication/testLogout.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
[{
"request": {
"method": "GET",
"url": "https:\/\/sandbox.familysearch.org\/platform\/collections\/tree",
"headers": {
"Host": "sandbox.familysearch.org",
"Accept-Encoding": null,
"User-Agent": "GuzzleHttp\/6.1.0 curl\/7.35.0 PHP\/5.5.9-1ubuntu4.9",
"Accept": "application\/x-gedcomx-v1+json"
}
},
"response": {
"status": {
"http_version": "1.1",
"code": "200",
"message": "OK"
},
"headers": {
"Cache-Control": "no-transform, max-age=604800",
"Content-Location": "\/collections\/tree",
"Content-Type": "application\/x-gedcomx-v1+json",
"Date": "Thu, 05 Nov 2015 21:14:44 GMT",
"Server": "Apache-Coyote\/1.1",
"Vary": "Accept, Accept-Language, Accept-Encoding, Expect, Accept-Encoding",
"X-PROCESSING-TIME": "0",
"transfer-encoding": "chunked",
"Connection": "Close",
"Access-Control-Allow-Methods": "OPTIONS, HEAD, GET, PUT, POST, DELETE",
"Access-Control-Allow-Headers": "accept, accept-charset, accept-encoding, accept-language, accept-datetime, authorization, connection, content-length, content-md5, content-type, date, expect, from, host, if-match, if-modified-since, if-none-match, if-range, if-unmodified-since, location, origin, range, referer, singularityjsheader, te, user-agent, warning, x-expect-override, x-reason, x-requested-with, x-fs-feature-tag",
"Access-Control-Expose-Headers": "location, link, warning, x-entity-id, content-location, x-processing-time, retry-after, x-fs-page-context, allow",
"Access-Control-Allow-Origin": "*",
"Access-Control-Max-Age": "604800"
},
"body": "{\n \"links\" : {\n \"source-references-query\" : {\n \"template\" : \"https:\/\/sandbox.familysearch.org\/platform\/tree\/source-references{?source,description,access_token}\",\n \"type\" : \"application\/json,application\/x-fs-v1+json,application\/x-fs-v1+xml,application\/x-gedcomx-v1+json,application\/x-gedcomx-v1+xml,application\/xml,text\/html\",\n \"accept\" : \"*\/*\",\n \"allow\" : \"GET\",\n \"title\" : \"Source References Query\"\n }\n },\n \"sourceDescriptions\" : [ {\n \"id\" : \"SD-FSFT\",\n \"about\" : \"#FSFT\",\n \"componentOf\" : {\n \"description\" : \"https:\/\/sandbox.familysearch.org\/platform\/collection\"\n },\n \"titles\" : [ {\n \"value\" : \"FamilySearch Family Tree\"\n } ],\n \"resourceType\" : \"http:\/\/gedcomx.org\/Collection\"\n } ],\n \"collections\" : [ {\n \"id\" : \"FSFT\",\n \"links\" : {\n \"person\" : {\n \"template\" : \"https:\/\/sandbox.familysearch.org\/platform\/tree\/persons\/{pid}{?skipDateNormalization,access_token}\",\n \"type\" : \"application\/json,application\/x-fs-v1+json,application\/x-fs-v1+xml,application\/x-gedcomx-v1+json,application\/x-gedcomx-v1+xml,application\/xml,text\/html\",\n \"accept\" : \"application\/x-fs-v1+json,application\/x-fs-v1+xml,application\/x-gedcomx-v1+json,application\/x-gedcomx-v1+xml\",\n \"allow\" : \"HEAD,GET,POST,DELETE\",\n \"title\" : \"Person\"\n },\n \"person-with-relationships\" : {\n \"template\" : \"https:\/\/sandbox.familysearch.org\/platform\/tree\/persons-with-relationships{?persons,person,access_token}\",\n \"type\" : \"application\/json,application\/x-fs-v1+json,application\/x-fs-v1+xml,application\/x-gedcomx-v1+json,application\/x-gedcomx-v1+xml,application\/xml,text\/html\",\n \"accept\" : \"*\/*\",\n \"allow\" : \"GET,POST,DELETE\",\n \"title\" : \"Person With Relationships\"\n },\n \"descendancy-query\" : {\n \"template\" : \"https:\/\/sandbox.familysearch.org\/platform\/tree\/descendancy{?spouse,personDetails,generations,marriageDetails,person,access_token}\",\n \"type\" : \"application\/json,application\/x-fs-v1+json,application\/x-fs-v1+xml,application\/x-gedcomx-v1+json,application\/x-gedcomx-v1+xml,application\/xml,text\/html\",\n \"accept\" : \"*\/*\",\n \"allow\" : \"GET\",\n \"title\" : \"Descendancy\"\n },\n \"self\" : {\n \"href\" : \"https:\/\/sandbox.familysearch.org\/platform\/collections\/tree\"\n },\n \"collection\" : {\n \"href\" : \"https:\/\/sandbox.familysearch.org\/platform\/collection\"\n },\n \"person-matches-query\" : {\n \"template\" : \"https:\/\/sandbox.familysearch.org\/platform\/tree\/matches{?count,q,candidateId,access_token}\",\n \"type\" : \"application\/atom+xml,application\/json,application\/x-gedcomx-atom+json,application\/xml,text\/html\",\n \"accept\" : \"*\/*\",\n \"allow\" : \"GET\",\n \"title\" : \"Person Matches Query\"\n },\n \"persons\" : {\n \"href\" : \"https:\/\/sandbox.familysearch.org\/platform\/tree\/persons\"\n },\n \"person-search\" : {\n \"template\" : \"https:\/\/sandbox.familysearch.org\/platform\/tree\/search{?count,start,q,context,access_token}\",\n \"type\" : \"application\/atom+xml,application\/json,application\/x-gedcomx-atom+json,application\/xml,text\/html\",\n \"accept\" : \"*\/*\",\n \"allow\" : \"GET\",\n \"title\" : \"Person Search\"\n },\n \"artifacts\" : {\n \"href\" : \"https:\/\/sandbox.familysearch.org\/platform\/memories\/memories\"\n },\n \"discussions\" : {\n \"href\" : \"https:\/\/sandbox.familysearch.org\/platform\/discussions\/discussions\"\n },\n \"preferred-spouse-relationship\" : {\n \"template\" : \"https:\/\/sandbox.familysearch.org\/platform\/tree\/users\/{uid}\/preferred-spouse-relationships\/{pid}{?access_token}\",\n \"type\" : \"application\/json,application\/x-fs-v1+json,application\/x-fs-v1+xml,application\/x-gedcomx-v1+json,application\/x-gedcomx-v1+xml,application\/xml,text\/html\",\n \"accept\" : \"application\/x-fs-v1+json,application\/x-fs-v1+xml,application\/x-gedcomx-v1+json,application\/x-gedcomx-v1+xml\",\n \"allow\" : \"HEAD,GET,PUT,DELETE\",\n \"title\" : \"Preferred Spouse Relationship\"\n },\n \"matches\" : {\n \"template\" : \"https:\/\/sandbox.familysearch.org\/platform\/tree\/persons\/{pid}\/matches{?count,status,includeNotAMatchDeclarations,confidence,collection,access_token}\",\n \"type\" : \"application\/atom+xml,application\/json,application\/x-gedcomx-atom+json,application\/xml,text\/html\",\n \"accept\" : \"application\/x-fs-v1+json,application\/x-fs-v1+xml,application\/x-gedcomx-v1+json,application\/x-gedcomx-v1+xml\",\n \"allow\" : \"GET,POST\",\n \"title\" : \"Person Matches\"\n },\n \"http:\/\/oauth.net\/core\/2.0\/endpoint\/token\" : {\n \"href\" : \"https:\/\/integration.familysearch.org\/cis-web\/oauth2\/v3\/token\"\n },\n \"logout\" : {\n \"href\" : \"https:\/\/sandbox.familysearch.org\/platform\/logout\"\n },\n \"current-user-history\" : {\n \"href\" : \"https:\/\/sandbox.familysearch.org\/platform\/users\/current\/history\"\n },\n \"http:\/\/oauth.net\/core\/2.0\/endpoint\/authorize\" : {\n \"href\" : \"https:\/\/integration.familysearch.org\/cis-web\/oauth2\/v3\/authorization\"\n },\n \"ancestry-query\" : {\n \"template\" : \"https:\/\/sandbox.familysearch.org\/platform\/tree\/ancestry{?spouse,personDetails,generations,descendants,marriageDetails,person,access_token}\",\n \"type\" : \"application\/json,application\/x-fs-v1+json,application\/x-fs-v1+xml,application\/x-gedcomx-v1+json,application\/x-gedcomx-v1+xml,application\/xml,text\/html\",\n \"accept\" : \"*\/*\",\n \"allow\" : \"GET\",\n \"title\" : \"Ancestry\"\n },\n \"current-user\" : {\n \"href\" : \"https:\/\/sandbox.familysearch.org\/platform\/users\/current\"\n },\n \"source-descriptions\" : {\n \"href\" : \"https:\/\/sandbox.familysearch.org\/platform\/sources\/descriptions\"\n },\n \"relationships\" : {\n \"href\" : \"https:\/\/sandbox.familysearch.org\/platform\/tree\/relationships\"\n },\n \"preferred-parent-relationship\" : {\n \"template\" : \"https:\/\/sandbox.familysearch.org\/platform\/tree\/users\/{uid}\/preferred-parent-relationships\/{pid}{?access_token}\",\n \"type\" : \"application\/json,application\/x-fs-v1+json,application\/x-fs-v1+xml,application\/x-gedcomx-v1+json,application\/x-gedcomx-v1+xml,application\/xml,text\/html\",\n \"accept\" : \"application\/x-fs-v1+json,application\/x-fs-v1+xml,application\/x-gedcomx-v1+json,application\/x-gedcomx-v1+xml\",\n \"allow\" : \"HEAD,GET,PUT,DELETE\",\n \"title\" : \"Preferred Parent Relationship\"\n },\n \"current-user-person\" : {\n \"href\" : \"https:\/\/sandbox.familysearch.org\/platform\/tree\/current-person\"\n }\n },\n \"title\" : \"FamilySearch Family Tree\"\n } ],\n \"description\" : \"#SD-FSFT\"\n}"
}
},{
"request": {
"method": "POST",
"url": "https:\/\/integration.familysearch.org\/cis-web\/oauth2\/v3\/token",
"headers": {
"Host": "integration.familysearch.org",
"Accept-Encoding": null,
"User-Agent": "GuzzleHttp\/6.1.0 curl\/7.35.0 PHP\/5.5.9-1ubuntu4.9",
"Accept": "application\/json",
"Expect": null,
"Content-Type": "application\/x-www-form-urlencoded"
},
"body": "grant_type=password&username=sdktester&password=1234sdkpass&client_id=a02j00000016dU8AAI"
},
"response": {
"status": {
"http_version": "1.1",
"code": "200",
"message": "OK"
},
"headers": {
"Server": "Apache-Coyote\/1.1",
"Pragma": "no-cache",
"Expires": "Thu, 01 Jan 1970 00:00:00 GMT",
"Cache-Control": "no-cache, no-store",
"Content-Type": "application\/json;charset=ISO-8859-1",
"Content-Language": "en-US",
"Content-Length": "185",
"Date": "Thu, 05 Nov 2015 21:14:44 GMT",
"Connection": "close",
"Access-Control-Allow-Methods": "OPTIONS, HEAD, GET, PUT, POST, DELETE",
"Access-Control-Allow-Headers": "accept, accept-charset, accept-encoding, accept-language, accept-datetime, authorization, connection, content-length, content-md5, content-type, date, expect, from, host, if-match, if-modified-since, if-none-match, if-range, if-unmodified-since, location, origin, range, referer, singularityjsheader, te, user-agent, warning, x-expect-override, x-reason, x-requested-with, x-fs-feature-tag",
"Access-Control-Expose-Headers": "location, link, warning, x-entity-id, content-location, x-processing-time, retry-after, x-fs-page-context, allow",
"Access-Control-Allow-Origin": "*",
"Access-Control-Max-Age": "604800"
},
"body": "{\"token\":\"USYS108F17A7B7049D316CAA9EA2681C289F_idses-int02.a.fsglobal.net\",\"access_token\":\"USYS108F17A7B7049D316CAA9EA2681C289F_idses-int02.a.fsglobal.net\",\"token_type\":\"family_search\"}"
}
},{
"request": {
"method": "GET",
"url": "https:\/\/sandbox.familysearch.org\/platform\/logout?access_token=USYS108F17A7B7049D316CAA9EA2681C289F_idses-int02.a.fsglobal.net",
"headers": {
"Host": "sandbox.familysearch.org",
"Accept-Encoding": null,
"User-Agent": "GuzzleHttp\/6.1.0 curl\/7.35.0 PHP\/5.5.9-1ubuntu4.9",
"Accept": null,
"Expect": null,
"Content-Type": "application\/x-www-form-urlencoded"
},
"body": "grant_type=password&username=sdktester&password=1234sdkpass&client_id=a02j00000016dU8AAI"
},
"response": {
"status": {
"http_version": "1.1",
"code": "405",
"message": "Method Not Allowed"
},
"headers": {
"Allow": "POST,OPTIONS",
"Content-Type": "application\/x-fs-v1+xml",
"Date": "Thu, 05 Nov 2015 21:14:45 GMT",
"Server": "Apache-Coyote\/1.1",
"Content-Length": "318",
"Connection": "Close",
"Access-Control-Allow-Methods": "OPTIONS, HEAD, GET, PUT, POST, DELETE",
"Access-Control-Allow-Headers": "accept, accept-charset, accept-encoding, accept-language, accept-datetime, authorization, connection, content-length, content-md5, content-type, date, expect, from, host, if-match, if-modified-since, if-none-match, if-range, if-unmodified-since, location, origin, range, referer, singularityjsheader, te, user-agent, warning, x-expect-override, x-reason, x-requested-with, x-fs-feature-tag",
"Access-Control-Expose-Headers": "location, link, warning, x-entity-id, content-location, x-processing-time, retry-after, x-fs-page-context, allow",
"Access-Control-Allow-Origin": "*",
"Access-Control-Max-Age": "604800"
},
"body": "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<fs:familysearch xmlns=\"http:\/\/gedcomx.org\/v1\/\" xmlns:fs=\"http:\/\/familysearch.org\/v1\/\" xmlns:atom=\"http:\/\/www.w3.org\/2005\/Atom\">\n <fs:error>\n <fs:code>405<\/fs:code>\n <fs:message>Method Not Allowed<\/fs:message>\n <\/fs:error>\n<\/fs:familysearch>\n"
}
}]

0 comments on commit 42a581a

Please sign in to comment.