{"metadata":{"image":[],"title":"","description":""},"api":{"url":"","auth":"required","results":{"codes":[]},"settings":"","params":[]},"next":{"description":"","pages":[]},"title":"Password based authentication","type":"basic","slug":"authentication-v4","excerpt":"","body":"Authentication to LRS Connect API uses OAuth 2.0. \n\n * User can find access token and refresh token using password-based authentication.\n * Data for inactive accounts will not be returned. \n[block:api-header]\n{\n \"type\": \"post\",\n \"title\": \"/rest/v4/oauth/token\"\n}\n[/block]\n\n[block:api-header]\n{\n \"type\": \"basic\",\n \"title\": \"Request\"\n}\n[/block]\nIn order to receive tokens,\n\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"curl --location --request POST 'https://connect.lrsus.com/rest/v4/oauth/token' \\\\\\n--header 'Content-Type: application/json' \\\\\\n--data-raw '{\\n \\\"scope\\\": \\\"OFFLINE_ACCESS\\\",\\n \\\"userName\\\": \\\"username\\\",\\n \\\"password\\\": \\\"password\\\",\\n \\\"grantType\\\": \\\"PASSWORD\\\"\\n}\\n'\",\n \"language\": \"curl\"\n },\n {\n \"code\": \"var myHeaders = new Headers();\\nmyHeaders.append(\\\"Content-Type\\\", \\\"application/json\\\");\\n\\nvar raw = JSON.stringify({\\\"scope\\\":\\\"OFFLINE_ACCESS\\\",\\\"userName\\\":\\\"username\\\",\\\"password\\\":\\\"password\\\",\\\"grantType\\\":\\\"PASSWORD\\\"});\\n\\nvar requestOptions = {\\n method: 'POST',\\n headers: myHeaders,\\n body: raw,\\n redirect: 'follow'\\n};\\n\\nfetch(\\\"https://connect.lrsus.com/rest/v4/oauth/token\\\", requestOptions)\\n .then(response => response.text())\\n .then(result => console.log(result))\\n .catch(error => console.log('error', error));\",\n \"language\": \"javascript\"\n },\n {\n \"code\": \"import http.client\\n\\nconn = http.client.HTTPSConnection(\\\"connect.lrsus.com\\\")\\npayload = \\\"{\\\\n \\\\\\\"scope\\\\\\\": \\\\\\\"OFFLINE_ACCESS\\\\\\\",\\\\n \\\\\\\"userName\\\\\\\": \\\\\\\"username\\\\\\\",\\\\n \\\\\\\"password\\\\\\\": \\\\\\\"password\\\\\\\",\\\\n \\\\\\\"grantType\\\\\\\": \\\\\\\"PASSWORD\\\\\\\"\\\\n}\\\\n\\\"\\nheaders = {\\n 'Content-Type': 'application/json'\\n}\\nconn.request(\\\"POST\\\", \\\"/rest/v4/oauth/token\\\", payload, headers)\\nres = conn.getresponse()\\ndata = res.read()\\nprint(data.decode(\\\"utf-8\\\"))\",\n \"language\": \"python\"\n },\n {\n \"code\": \"#import <Foundation/Foundation.h>\\n\\ndispatch_semaphore_t sema = dispatch_semaphore_create(0);\\n\\nNSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString::::at:::\\\"https://connect.lrsus.com/rest/v4/oauth/token\\\"]\\n cachePolicy:NSURLRequestUseProtocolCachePolicy\\n timeoutInterval:10.0];\\nNSDictionary *headers = @{\\n @\\\"Content-Type\\\": @\\\"application/json\\\"\\n};\\n\\n[request setAllHTTPHeaderFields:headers];\\nNSData *postData = [[NSData alloc] initWithData:[@\\\"{\\\\n \\\\\\\"scope\\\\\\\": \\\\\\\"OFFLINE_ACCESS\\\\\\\",\\\\n \\\\\\\"userName\\\\\\\": \\\\\\\"username\\\\\\\",\\\\n \\\\\\\"password\\\\\\\": \\\\\\\"password\\\\\\\",\\\\n \\\\\\\"grantType\\\\\\\": \\\\\\\"PASSWORD\\\\\\\"\\\\n}\\\\n\\\" dataUsingEncoding:NSUTF8StringEncoding]];\\n[request setHTTPBody:postData];\\n\\n[request setHTTPMethod:@\\\"POST\\\"];\\n\\nNSURLSession *session = [NSURLSession sharedSession];\\nNSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request\\ncompletionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {\\n if (error) {\\n NSLog(@\\\"%@\\\", error);\\n dispatch_semaphore_signal(sema);\\n } else {\\n NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;\\n NSError *parseError = nil;\\n NSDictionary *responseDictionary = [NSJSONSerialization JSONObjectWithData:data options:0 error:&parseError];\\n NSLog(@\\\"%@\\\",responseDictionary);\\n dispatch_semaphore_signal(sema);\\n }\\n}];\\n[dataTask resume];\\ndispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);\",\n \"language\": \"objectivec\"\n }\n ]\n}\n[/block]\n\n[block:api-header]\n{\n \"title\": \"Request Body\"\n}\n[/block]\n \n[block:parameters]\n{\n \"data\": {\n \"h-0\": \"Key\",\n \"h-1\": \"Description\",\n \"h-2\": \"Default value\",\n \"0-0\": \"scope\",\n \"0-1\": \"The scope of authentication. Provide scope as OFFLINE_ACCESS.\",\n \"1-0\": \"userName\",\n \"1-1\": \"The user name of the user.\",\n \"2-0\": \"password\",\n \"2-1\": \"The password of the user.\",\n \"3-0\": \"grantType\",\n \"3-1\": \"The authentication grant type. Provide authentication grant type as PASSWORD.\"\n },\n \"cols\": 2,\n \"rows\": 4\n}\n[/block]\n\n[block:api-header]\n{\n \"type\": \"basic\",\n \"title\": \"Response 200 (application/json)\"\n}\n[/block]\nThe response will contain a \"Bearer\" token that must be passed on subsequent requests. The token is valid for 3600 seconds by default. The response also contains a refresh token which can be used to fetch the bearer token again.\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"{\\n \\\"tokenType\\\": \\\"Bearer\\\",\\n \\\"expiresIn\\\": \\\"3600\\\",\\n \\\"accessToken\\\": \\\"eyJraWQiOiJJQVE3czZMeFNmdW03SWFhYjNocEtiM0R5dGJta2Jic2dwUzVGRElnR2I4IiwiYWxnIjoiUlMyNTYifQ.eyJ2ZXIiOjEsImp0aSI6IkFULnJ4TUFpYmtBZEJiUHMtYzBlOERmWm5rZUZRU0lzc01WQk51R1RFSGhMVXcub2FyeTFyazI5R3dFbmtNWDEwaDYiLCJpc3MiOiJodHRwczovL2Rldi05MTA3NDEub2t0YXByZXZpZXcuY29tL29hdXRoMi9hdXNianF0YmVpRURlcjZRVDBoNyIsImF1ZCI6Imh0dHBzOi8vYXBpLnN0b3JtcGF0aC5jb20vdjEvYXBwbGljYXRpb25zLzVzdW10Z2h3cDZWTDZxR1NtQ3dUMmMiLCJpYXQiOjE2MTUzNjg2NTIsImV4cCI6MTYxNTM3MjI1MiwiY2lkIjoiMG9hYmpwNW4wYVFQVzNBR0UwaDciLCJ1aWQiOiIwMHVmcGE0ZtIn0.skBZEwFaKHTYCX10889fvJlFd9eLDmxSmiFm78_x7e-TpgxrXI6No-1FqYZ4eFgBLLaBB3Ljet1Ifj0feBvGiXT5RbmYk0MxtaCqq3MN-eEin5-D1WbEkC80NltXhkb8wyN_fyTUn8epFs_gec2DE4-TO99w4WVeKOMHeJacFks6TJby77mXrL8KmB5BOQsck3cEypkP6M5Lnwv5uc-sbL1GI5qB0VZwGPrhdDkRCywzDCIfmJyxvcrh9h0AgyVTjqa4B1OXAIoeFn71YAg9D-3vMvW1NIaBvoh3NRynGeJ3af6ZiIHPDLjPMLESKChw-L_GklbV2Iy1OAo0c7iBIQ\\\",\\n \\\"scope\\\": \\\"offline_access\\\",\\n \\\"refreshToken\\\": \\\"wZNBvgaPrP_SzjWvZd90Wpc5KmuC3xs18b32323230\\\"\\n}\",\n \"language\": \"json\",\n \"name\": \"JSON\"\n }\n ]\n}\n[/block]\nThe token is passed as an Authorization header value. \n[block:parameters]\n{\n \"data\": {\n \"h-0\": \"Header\",\n \"h-1\": \"Value\",\n \"h-2\": \"Description\",\n \"0-0\": \"Authorization\",\n \"0-1\": \"Example:\\n\\nBearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE0MzU3N...FWFxGl3odgJ25T0O7kwq-hca2QDtSIWKUFHTpBNU97c\",\n \"0-2\": \"Concatenate value of \\\"Bearer\\\" and `access_token` returned from /rest/v3/oauth/token method.\"\n },\n \"cols\": 3,\n \"rows\": 1\n}\n[/block]\n\n[block:api-header]\n{\n \"type\": \"basic\",\n \"title\": \"SSL\"\n}\n[/block]\nSSL is used to encrypt all requests to & from LRS Connect API.","updates":[],"order":2,"isReference":false,"hidden":false,"sync_unique":"","link_url":"","link_external":false,"_id":"60488fca1722dc0039f7ef25","createdAt":"2021-03-10T09:22:18.293Z","user":"5b920d513f726700030ef67d","category":{"sync":{"isSync":false,"url":""},"pages":[],"title":"Documentation","slug":"documentation","order":0,"from_sync":false,"reference":false,"_id":"58766da64a24f82f00bbf286","version":"58766da54a24f82f00bbf285","project":"552819c1555b9e0d00564f74","createdAt":"2015-04-10T18:43:14.538Z","__v":0},"version":{"version":"3.0","version_clean":"3.0.0","codename":"","is_stable":true,"is_beta":false,"is_hidden":false,"is_deprecated":false,"categories":["58766da64a24f82f00bbf286","5e97f10ca9631a0231d9c19a"],"_id":"58766da54a24f82f00bbf285","releaseDate":"2017-01-11T17:38:45.993Z","project":"552819c1555b9e0d00564f74","__v":2,"createdAt":"2017-01-11T17:38:45.993Z"},"project":"552819c1555b9e0d00564f74","__v":0,"parentDoc":null}