{"__v":1,"_id":"54d94b3c6a09052100a6b699","category":{"__v":6,"_id":"53fe7d89addab8973c1af2b0","pages":["53fe7e17addab8973c1af2bb","53fe80ebaddab8973c1af2be","54011f0ec1c1764f69827203","53fe8159addab8973c1af2c1","53fe81ecaddab8973c1af2c5","54d94b3c6a09052100a6b699","56d49a9da4a9211b00c8f118"],"project":"53fe6dc5addab8973c1af267","version":"53fe6dc5addab8973c1af26a","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2014-08-28T00:53:29.717Z","from_sync":false,"order":6,"slug":"logout-reference","title":"Logout Reference"},"parentDoc":null,"project":"53fe6dc5addab8973c1af267","user":"53fe6d8baddab8973c1af266","version":{"__v":19,"_id":"53fe6dc5addab8973c1af26a","project":"53fe6dc5addab8973c1af267","createdAt":"2014-08-27T23:46:13.941Z","releaseDate":"2014-08-27T23:46:13.941Z","categories":["53fe6dc5addab8973c1af26b","53fe71a2addab8973c1af276","53fe7d89addab8973c1af2b0","53fe7d8daddab8973c1af2b1","53fe836faddab8973c1af2ce","53ff9a4823a37e1d5cebafe1","53ff9e3723a37e1d5cebaff7","53ffaca523a37e1d5cebb039","53ffad2e23a37e1d5cebb03c","5400c7d2ec93b29b61d4f7be","5400f0e1ec93b29b61d4f7dd","54d5636323010a0d001aca81","54d565c1276f8e0d00feab54","54ff40532882a10d00546927","556606d25561af0d008208b7","558c91900b236c2500d37c9a","56180a14f8c9632100ac7599","564fb3a59b4fab1700187518","5702e2d2f2d6f336005e901f"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-02-10T00:05:16.548Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"auth":"required","params":[],"url":""},"isReference":false,"order":5,"body":"# Using per-login logout hooks\n\nWith the standard Clef logout hook, you set the logout hook in your application configuration. With per-login Clef logout hooks, you can pass a URL to be hit as the logout hook every time a user logs in. This allows more flexibility in specifying exactly where a user should be logged out.\n\nUsing this version of the logout hook is very easy. When you do the [`authorize` portion of the OAuth handshake](/v1.0/docs/authenticating-users), just specify the URL to be hit for logout. This URL must conform to the [same-domain policy for logout hooks](/v1.0/docs/creating-a-clef-application).\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"require 'httparty'\\nrequire 'json'\\n\\nAPP_ID = '6f8fb6e642924a5e9e7deacf35292abf'\\nAPP_SECRET = '27788a6c0934331258651af709813ba2'\\n\\ncode = params[:code]\\n\\ndata = {\\n    body: {\\n        code: code,\\n        app_id: APP_ID,\\n        app_secret: APP_SECRET,\\n        logout_hook: 'http://example.com/your/custom/logout/hook'\\n    }\\n}\\n\\nurl = \\\"https://clef.io/api/v1/authorize\\\"\\n\\nresponse = HTTParty.post(url, data)\\n\\nif response['success']\\n    access_token = response['access_token']\\nelse\\n    p response['error']\\nend\",\n      \"language\": \"ruby\"\n    },\n    {\n      \"code\": \"import requests\\nimport json\\n\\nAPP_ID = '8c9253dca23777745c9102e0be99ea70'\\nAPP_SECRET = 'a9a356f16c77bdcddf15f0a1c407dd3a'\\n\\ncode = request.args.get('code')\\n\\ndata = {\\n    'app_id': APP_ID,\\n    'app_secret': APP_SECRET,\\n    'code': code,\\n  \\t'logout_hook': 'http://example.com/your/custom/logout/hook'\\n}\\n\\nurl = 'https://clef.io/api/v1/authorize'\\n\\nresponse = requests.post(url, data=data)\\njson_response = json.loads(response.text)\\n\\nif json_response.get('success', False):\\n    access_token = json_response['access_token']\\nelse:\\n    print json_response['error']\\n                            \",\n      \"language\": \"python\"\n    },\n    {\n      \"code\": \"<?php\\n\\n$app_id = '562306be5c59cc3f2da25095c05da670';\\n$app_secret = '9fd4e0d1e240e6f95b20a6223c3edbfc';\\n\\n$code = $_GET[\\\"code\\\"];\\n\\n$postdata = http_build_query(\\n    array(\\n        'code' => $code,\\n        'app_id' => $app_id,\\n        'app_secret' => $app_secret,\\n      \\t'logout_hook' => 'http://example.com/your/custom/logout/hook'\\n    )\\n);\\n\\n$opts = array('http' =>\\n    array(\\n        'method'  => 'POST',\\n        'header'  => 'Content-type: application/x-www-form-urlencoded',\\n        'content' => $postdata\\n    )\\n);\\n\\n$url = 'https://clef.io/api/v1/authorize';\\n\\n$context  = stream_context_create($opts);\\n$response = file_get_contents($url, false, $context);\\n$response = json_decode($response, true);\\n\\nif ($response && $response['success']) {\\n    $access_token = $response['access_token'];\\n} else {\\n    echo $response['error'];\\n}\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"per-login-logout-hooks","type":"basic","title":"Per-login logout hooks"}

Per-login logout hooks


# Using per-login logout hooks With the standard Clef logout hook, you set the logout hook in your application configuration. With per-login Clef logout hooks, you can pass a URL to be hit as the logout hook every time a user logs in. This allows more flexibility in specifying exactly where a user should be logged out. Using this version of the logout hook is very easy. When you do the [`authorize` portion of the OAuth handshake](/v1.0/docs/authenticating-users), just specify the URL to be hit for logout. This URL must conform to the [same-domain policy for logout hooks](/v1.0/docs/creating-a-clef-application). [block:code] { "codes": [ { "code": "require 'httparty'\nrequire 'json'\n\nAPP_ID = '6f8fb6e642924a5e9e7deacf35292abf'\nAPP_SECRET = '27788a6c0934331258651af709813ba2'\n\ncode = params[:code]\n\ndata = {\n body: {\n code: code,\n app_id: APP_ID,\n app_secret: APP_SECRET,\n logout_hook: 'http://example.com/your/custom/logout/hook'\n }\n}\n\nurl = \"https://clef.io/api/v1/authorize\"\n\nresponse = HTTParty.post(url, data)\n\nif response['success']\n access_token = response['access_token']\nelse\n p response['error']\nend", "language": "ruby" }, { "code": "import requests\nimport json\n\nAPP_ID = '8c9253dca23777745c9102e0be99ea70'\nAPP_SECRET = 'a9a356f16c77bdcddf15f0a1c407dd3a'\n\ncode = request.args.get('code')\n\ndata = {\n 'app_id': APP_ID,\n 'app_secret': APP_SECRET,\n 'code': code,\n \t'logout_hook': 'http://example.com/your/custom/logout/hook'\n}\n\nurl = 'https://clef.io/api/v1/authorize'\n\nresponse = requests.post(url, data=data)\njson_response = json.loads(response.text)\n\nif json_response.get('success', False):\n access_token = json_response['access_token']\nelse:\n print json_response['error']\n ", "language": "python" }, { "code": "<?php\n\n$app_id = '562306be5c59cc3f2da25095c05da670';\n$app_secret = '9fd4e0d1e240e6f95b20a6223c3edbfc';\n\n$code = $_GET[\"code\"];\n\n$postdata = http_build_query(\n array(\n 'code' => $code,\n 'app_id' => $app_id,\n 'app_secret' => $app_secret,\n \t'logout_hook' => 'http://example.com/your/custom/logout/hook'\n )\n);\n\n$opts = array('http' =>\n array(\n 'method' => 'POST',\n 'header' => 'Content-type: application/x-www-form-urlencoded',\n 'content' => $postdata\n )\n);\n\n$url = 'https://clef.io/api/v1/authorize';\n\n$context = stream_context_create($opts);\n$response = file_get_contents($url, false, $context);\n$response = json_decode($response, true);\n\nif ($response && $response['success']) {\n $access_token = $response['access_token'];\n} else {\n echo $response['error'];\n}", "language": "php" } ] } [/block]