{"metadata":{"image":[],"title":"","description":""},"api":{"url":"","auth":"required","params":[],"results":{"codes":[]},"settings":""},"next":{"description":"","pages":[]},"title":"Authentication","type":"basic","slug":"authentication","excerpt":"Proving that you have access to the right account","body":"All requests require an OAuth 2 access token. You can generate an access token in your [account settings](https://cloud.lifx.com/settings). Take care to keep access tokens private as they grant remote access to your lights.\n\nAuthenticate with HTTP Basic Authentication or the HTTP Authorization header. When using HTTP Basic Authentication the access token is the username and the password may be left blank. Bad access tokens will be rejected by responding with a `401 Forbidden` status code.\n[block:callout]\n{\n  \"type\": \"danger\",\n  \"body\": \"All requests must be made over HTTPS. Requests made to the HTTP endpoint will be rejected with a `426 Upgrade Required` status code indicating that the connection must be remade using HTTPS to continue.\",\n  \"title\": \"HTTPS Requests Only\"\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"HTTP Authorization Header\"\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"curl -H \\\"Authorization: Bearer [[app:Token]]\\\" \\\"https://api.lifx.com/v1/lights/all\\\"\",\n      \"language\": \"curl\"\n    },\n    {\n      \"code\": \"<?php\\n\\n$link = \\\"https://api.lifx.com/v1/lights/all\\\";\\n$authToken = \\\"[[app:Token]]\\\";\\n$ch = curl_init($link);\\n$headers = array('Authorization: Bearer ' . $authToken);\\ncurl_setopt($ch, CURLOPT_HTTPHEADER, $headers);\\n$response = curl_exec($ch);\\n\\n?>\\n\",\n      \"language\": \"php\"\n    },\n    {\n      \"code\": \"import requests\\n\\ntoken = \\\"[[app:Token]]\\\"\\n\\nheaders = {\\n    \\\"Authorization\\\": \\\"Bearer %s\\\" % token,\\n}\\n\\nresponse = requests.get('https://api.lifx.com/v1/lights/all', headers=headers)\",\n      \"language\": \"python\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"HTTP Basic Authentication\"\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"curl -u \\\"[[app:Token]]:\\\" \\\"https://api.lifx.com/v1/lights/all\\\"\",\n      \"language\": \"curl\"\n    },\n    {\n      \"code\": \"<?php\\n\\n$link = \\\"https://api.lifx.com/v1/lights/all\\\";\\n$authToken = \\\"[[app:Token]]\\\";\\n$ch = curl_init($link);\\ncurl_setopt($ch, CURLOPT_USERPWD, $authToken . \\\":\\\");\\n$response = curl_exec($ch);\\n\\n?>\",\n      \"language\": \"php\"\n    },\n    {\n      \"code\": \"import requests\\n\\ntoken = \\\"[[app:Token]]\\\"\\n\\nresponse = requests.get('https://api.lifx.com/v1/lights/all', auth=(token, ''))\\n\",\n      \"language\": \"python\"\n    }\n  ]\n}\n[/block]","updates":["5620f09ab244890d001868dc"],"order":0,"isReference":false,"hidden":false,"sync_unique":"","link_url":"","link_external":false,"_id":"55f28173f9f3991900f38a17","user":"557e2561eb75d80d00af3dab","createdAt":"2015-06-17T04:27:46.162Z","version":{"version":"1","version_clean":"1.0.0","codename":"","is_stable":true,"is_beta":false,"is_hidden":false,"is_deprecated":false,"categories":["55f28172f9f3991900f38a14","55f28172f9f3991900f38a15","55f28172f9f3991900f38a16","55f66acb297b37170058accb","5d229ff5e59b8e003ab3a9da"],"_id":"55f28172f9f3991900f38a13","project":"54ebb40d6423300d003672c0","releaseDate":"2015-09-11T07:23:30.065Z","createdAt":"2015-09-11T07:23:30.065Z","__v":3},"__v":4,"category":{"sync":{"isSync":false,"url":""},"pages":["55f28173f9f3991900f38a17","55f28173f9f3991900f38a18","55f28173f9f3991900f38a19","55f28173f9f3991900f38a1a","55f28173f9f3991900f38a1b","55f28173f9f3991900f38a1c"],"title":"Overview","slug":"overview","order":1,"from_sync":false,"reference":false,"_id":"55f28172f9f3991900f38a15","version":"55f28172f9f3991900f38a13","__v":1,"createdAt":"2015-06-17T04:27:26.544Z","project":"54ebb40d6423300d003672c0"},"project":"54ebb40d6423300d003672c0","githubsync":"","parentDoc":null}

Authentication

Proving that you have access to the right account

All requests require an OAuth 2 access token. You can generate an access token in your [account settings](https://cloud.lifx.com/settings). Take care to keep access tokens private as they grant remote access to your lights. Authenticate with HTTP Basic Authentication or the HTTP Authorization header. When using HTTP Basic Authentication the access token is the username and the password may be left blank. Bad access tokens will be rejected by responding with a `401 Forbidden` status code. [block:callout] { "type": "danger", "body": "All requests must be made over HTTPS. Requests made to the HTTP endpoint will be rejected with a `426 Upgrade Required` status code indicating that the connection must be remade using HTTPS to continue.", "title": "HTTPS Requests Only" } [/block] [block:api-header] { "type": "basic", "title": "HTTP Authorization Header" } [/block] [block:code] { "codes": [ { "code": "curl -H \"Authorization: Bearer [[app:Token]]\" \"https://api.lifx.com/v1/lights/all\"", "language": "curl" }, { "code": "<?php\n\n$link = \"https://api.lifx.com/v1/lights/all\";\n$authToken = \"[[app:Token]]\";\n$ch = curl_init($link);\n$headers = array('Authorization: Bearer ' . $authToken);\ncurl_setopt($ch, CURLOPT_HTTPHEADER, $headers);\n$response = curl_exec($ch);\n\n?>\n", "language": "php" }, { "code": "import requests\n\ntoken = \"[[app:Token]]\"\n\nheaders = {\n \"Authorization\": \"Bearer %s\" % token,\n}\n\nresponse = requests.get('https://api.lifx.com/v1/lights/all', headers=headers)", "language": "python" } ] } [/block] [block:api-header] { "type": "basic", "title": "HTTP Basic Authentication" } [/block] [block:code] { "codes": [ { "code": "curl -u \"[[app:Token]]:\" \"https://api.lifx.com/v1/lights/all\"", "language": "curl" }, { "code": "<?php\n\n$link = \"https://api.lifx.com/v1/lights/all\";\n$authToken = \"[[app:Token]]\";\n$ch = curl_init($link);\ncurl_setopt($ch, CURLOPT_USERPWD, $authToken . \":\");\n$response = curl_exec($ch);\n\n?>", "language": "php" }, { "code": "import requests\n\ntoken = \"[[app:Token]]\"\n\nresponse = requests.get('https://api.lifx.com/v1/lights/all', auth=(token, ''))\n", "language": "python" } ] } [/block]