{"__v":12,"_id":"564d1afc4567342100ad96ca","category":{"__v":2,"_id":"564d1af94567342100ad96ad","pages":["564d1afb4567342100ad96c0","564d1afb4567342100ad96c1","564d1afb4567342100ad96c2","564d1afb4567342100ad96c3","564d1c209f8c5c0d00245e15"],"project":"551375e1d04af219007ddc52","version":"564d1af84567342100ad96aa","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-03-27T02:56:41.497Z","from_sync":false,"order":2,"slug":"authenticating-users","title":"Authenticating Users"},"project":"551375e1d04af219007ddc52","user":"5539912a0074c80d00621b14","version":{"__v":1,"_id":"564d1af84567342100ad96aa","project":"551375e1d04af219007ddc52","createdAt":"2015-11-19T00:42:32.705Z","releaseDate":"2015-11-19T00:42:32.705Z","categories":["564d1af94567342100ad96ab","564d1af94567342100ad96ac","564d1af94567342100ad96ad","564d1af94567342100ad96ae","564d1af94567342100ad96af","564d1af94567342100ad96b0","564d1af94567342100ad96b1","564d1af94567342100ad96b2"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.1.0","version":"1.1"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-08-13T22:23:27.363Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":2,"body":"This page will help you get started with Human API for iOS. You'll be up and running in no time! If you haven't already, please create a developer account as described on the [Start Here](doc:start-here) page and come back here when you're done. \n\n#Overview\nThere are two main parts to integrating Human API with your application:\n* **A:** Allowing your users to authenticate their data\n* **B:** Accessing authenticated user data\n\nThis guide will walk through the implementation of the Human API iOS SDK to handle **part A** by allowing your users to authenticate their data within your application via the Human Connect popup . After the authentication process is complete, you will have the credentials needed to access user data from your server to complete **part B** as detailed in the [Data Retrieval](doc:data-overview) section of the documentation.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/f0A9h1fgTeynYJsK1OXm_kannnect-ios.png\",\n        \"kannnect-ios.png\",\n        \"897\",\n        \"1518\",\n        \"#5cb9ac\",\n        \"\"\n      ],\n      \"caption\": \"Connect on iOS\",\n      \"sizing\": \"smart\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Add the SDK to your Application\"\n}\n[/block]\nCopy the `HumanAPI` folder from [the master branch of the iOS SDK](https://github.com/humanapi/humanapi-ios-client/) and place it in the base level of your project directory.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Configure and Launch Human Connect\"\n}\n[/block]\nNow that you have the SDK, it's time to set up the authentication flow.\n\nA user authenticates Human API by clicking the Connect Health Data button and authenticating their data directly with your application via Human Connect.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/Ux0rUeXTRoup2PJ7oY4L_blue.png\",\n        \"blue.png\",\n        \"259\",\n        \"49\",\n        \"#4184c4\",\n        \"\"\n      ]\n    }\n  ]\n}\n[/block]\nYou can easily embed this authentication process directly into your iOS application. \n\nFirst, add the button above (or another button of your choosing) as a `UIButton` to the view you would like to launch Connect from and link it to an `IBAction` in the view controller. You can then use this button to launch Human Connect in the following three steps:\n\n#1. Import the SDK ViewController and Protocol\nIn your ViewController.h file:\n  * `#import \"HumanConnectViewController.h\"` at the top\n  * Add `<HumanAPINotifications>` protocol to the ViewController\n  e.g. `:::at:::interface ViewController : UIViewController  <HumanAPINotifications>`\n\n#2. Instantiate the HumanConnectViewController\nWithin the IBAction function you created, instantiate the `HumanConnectViewController`:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"NSString *myClientID = @\\\"<Your-Client-ID>\\\";\\nNSString *authURL = @\\\"http://localhost:3000/sessionToken\\\";\\n    \\n    \\nHumanConnectViewController *hcvc = [[HumanConnectViewController alloc] initWithClientID:myClientID                                                     andAuthURL:authURL];\\n  \\nhcvc.delegate = self;\\n[self presentViewController:hcvc animated:YES completion:nil];\",\n      \"language\": \"objectivec\"\n    },\n    {\n      \"code\": \"let clientId : String = \\\"659e9bd58ec4ee7fa01bc6b4627cb37e5c13ec21\\\"\\nlet authURL : String = \\\"http://localhost:3000/sessionToken\\\"\\n\\n\\nlet hcvc : HumanConnectViewController = HumanConnectViewController(clientID: clientId, andAuthURL: authURL);\\n\\nhcvc.delegate = self;\\n\\nself.presentViewController(hcvc, animated: true, completion: nil);\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]\nYou will need to pass these two values into the constructor:\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"Name\",\n    \"h-1\": \"Description\",\n    \"0-0\": \"`clientId`\",\n    \"1-0\": \"`authURL`\",\n    \"0-1\": \"Unique ID of your developer portal application (found on the application settings page).\",\n    \"1-1\": \"Custom endpoint on your server to handle the user token exchange.\\n(You can add the default for now, we'll be implementing this in the second half of this guide.)\"\n  },\n  \"cols\": 2,\n  \"rows\": 2\n}\n[/block]\n#3. Launch Connect for the User\n\nUse `startConnectFlowForNewUser: (NSString *)userId` to launch Connect for a new user and pass it the unique ID of the user in your system (This will be returned in the final step so that you can associate Human API credentials with the correct user.)\n\n\nFor now, this is all you need, but be aware that the next time the user launches Connect, you will need to use `startConnectFlowFor: (NSString *)userId andPublicToken: (NSString *)publicToken`. You will get this token after the first successful authentication.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[hcvc startConnectFlowForNewUser:locaUser.email];\\n \\n//If you have a publicToken for the user, supply it to Human Connect on launch\\n//[hcvc startConnectFlowFor:localUser.email andPublicToken:localUser.publicToken];\\n\",\n      \"language\": \"objectivec\"\n    },\n    {\n      \"code\": \"hcvc.startConnectFlowForNewUser(localUser.email);\\n \\n//If you have a publicToken for the user, supply it to Human Connect on launch\\n// hcvc.startConnectFlowFor(\\\"localUser.email\\\", andPublicToken: \\\"localUser.publicToken\\\")\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"title\": \"PublicToken\",\n  \"body\": \"You will receive a `publicToken` at the end of the user authentication process. This value must be passed into Human Connect every time the user opens the popup thereafter. It is not necessary for the first launch.\"\n}\n[/block]\n#Complete Launch Implementation\nAltogether, your launch code for Human Connect should now look something like this:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"/* ViewController.h */\\n\\n#import <UIKit/UIKit.h>\\n#import \\\"HumanConnectViewController.h\\\"\\n\\n\\n@interface ViewController : UIViewController  <HumanAPINotifications>\\n\\n\\n@end\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"/* ViewController.m */\\n\\n#import \\\"ViewController.h\\\"\\n\\n@interface ViewController ()\\n\\n@end\\n\\n@implementation ViewController\\n\\n- (void)viewDidLoad {\\n    [super viewDidLoad];\\n    // Do any additional setup after loading the view, typically from a nib.\\n}\\n\\n- (void)didReceiveMemoryWarning {\\n    [super didReceiveMemoryWarning];\\n    // Dispose of any resources that can be recreated.\\n}\\n\\n- (IBAction)launchHumanConnect:(id)sender {\\n    \\n    NSString *myClientID = @\\\"<Your-Client-ID>\\\";\\n    NSString *authURL = @\\\"http://localhost:3000/sessionToken\\\";\\n    \\n    \\n    HumanConnectViewController *hcvc = [[HumanConnectViewController alloc] initWithClientID:myClientID                                                     andAuthURL:authURL];\\n  \\n    hcvc.delegate = self;\\n    [self presentViewController:hcvc animated:YES completion:nil];\\n    \\n\\n    [hcvc startConnectFlowForNewUser:locaUser.email];\\n\\n    //If you have a publicToken for the user, supply it to Human Connect on launch\\n    //[hcvc startConnectFlowFor: localUser.email\\n    //           andPublicToken: localUser.publicToken];\\n    \\n}\\n\\n@end\",\n      \"language\": \"objectivec\"\n    },\n    {\n      \"code\": \"import UIKit\\n\\nclass ViewController: UIViewController, HumanAPINotifications {\\n\\n    override func viewDidLoad() {\\n        super.viewDidLoad()\\n    }\\n\\n    override func didReceiveMemoryWarning() {\\n        super.didReceiveMemoryWarning()\\n    }\\n\\n    @IBAction func launchConnect(sender: UIButton) {\\n        let clientId : String = \\\"<Your-Client-ID>\\\"\\n        let authURL : String = \\\"http://localhost:3000/sessionToken\\\"\\n               \\n        let hcvc : HumanConnectViewController = HumanConnectViewController(clientID: clientId, andAuthURL: authURL);\\n        \\n        hcvc.delegate = self;\\n        self.presentViewController(hcvc, animated: true, completion: nil);\\n        \\n        //Use your local user identifier here\\n        hcvc.startConnectFlowForNewUser(\\\"localUser.email\\\");\\n\\n\\t\\t\\t  //If you have a publicToken for the user, supply it to Human Connect on launch\\n    \\t\\t// hcvc.startConnectFlowFor(\\\"localUser.email\\\", andPublicToken: \\\"localUser.publicToken\\\")\\n\\n    }\\n\\n}\\n\\n\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"title\": \"iOS 9+\",\n  \"body\": \"If your authURL does not have SSL (https) such as the localhost example above, you will need to configure an App Transport Security Exception so that iOS does not block the POST request to an insecure URL. See the guide [here](http://ste.vn/2015/06/10/configuring-app-transport-security-ios-9-osx-10-11/) for more information.\"\n}\n[/block]\nThat is all that is needed to correctly launch Human Connect to allow your users to authenticate their data. The second half of the authentication process will occur on your server at the `authURL` endpoint.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"[Server-Side] Handle Token Exchange\"\n}\n[/block]\nWhen a user authenticates a new data source in Human Connect, the Connect SDK will POST a `sessionTokenObject` to your server for final processing via the `authURL` specified on launch.\n\nTo complete the token exchange process, you should:\n   1. Add your `clientSecret` to the `sessionTokenObject` \n     (clientSecret can be found on the app settings page in the developer portal)\n    \n   2. POST the modified `sessionTokenObject` from your server to Human API Tokens Endpoint:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"   https://user.humanapi.co/v1/connect/tokens\",\n      \"language\": \"curl\"\n    }\n  ]\n}\n[/block]\n   3. Retrieve and store `humanId`, `accessToken` and `publicToken` on your server with the user model to be used to query user data from Human API. \n     ([See here](http://hub.humanapi.co/docs/overview-of-human-connect#key-data-points) for more information on what these values are.)\n    \n   4. Return status `200` or `201` with payload containing `publicToken` to store on device for future launches of Human Connect:   \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"   { publicToken: \\\"2767d6oea95f4c3db8e8f3d0a1238302\\\" }\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n Here's an example of what this endpoint might look like in Node.js:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"//Endpoint for specified 'authURL'\\napp.post('/sessionToken', function(req, res, next) {\\n\\n  var sessionTokenObject = req.body;\\n  // grab client secret from app settings page and `sign` `sessionTokenObject` with it.\\n  sessionTokenObject.clientSecret = '<Your-Client-Secret>';\\n\\n  request({\\n    method: 'POST',\\n    uri: 'https://user.humanapi.co/v1/connect/tokens',\\n    json: sessionTokenObject\\n  }, function(err, resp, body) {\\n      if(err) return res.send(422);\\n\\n       //Use these values to determine which user launched Connect\\n      console.log(\\\"clientId =\\\"+ body.clientId);\\n      console.log(\\\"clientId =\\\"+ body.clientId);\\n\\n      /* Human API credentials. \\n      Save these with the user model in your system. */\\n      console.log(\\\"humanId = \\\" + body.humanId);\\n      console.log(\\\"accessToken = \\\"+ body.accessToken);\\n      console.log(\\\"publicToken = \\\"+ body.publicToken);\\n\\n\\n      //Send back publicToken to Android app\\n      var responseJSON = {publicToken: body.publicToken};\\n\\n      res.setHeader('Content-Type', 'application/json');\\n      res.status(201).send(JSON.stringify(responseJSON));\\n    });\\n});\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n\nFor more information on the server implementation, see [Finalizing User Authentication](http://hub.humanapi.co/docs/integrating-human-connect#finalize-the-user-authentication).\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Handle Callbacks from Human Connect\"\n}\n[/block]\nWhen the token exchange process is complete on your server, the Human API SDK will deliver your response to the `(void) onConnectSuccess: (NSDictionary *)data` & `(void) onConnectFailure:(NSString *)error` callbacks on the user's device.\n\n#onConnectSuccess\nHere, you should save the returned `publicToken` on the device so that you can supply it to the HumanConnectViewController whenever the user launches Connect again in the future.\n\n#onConnectFailure\nThis is called when there is an error from Connect. Implementation of this callback is this therefore optional.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"/** Connect success handler */\\n- (void)onConnectSuccess:(NSDictionary *)data\\n{\\n    NSLog(@\\\"Connect success!  publicToken=\\\\n %@\\\", data);\\n    \\n     //Notify user of success\\n    //Save publicToken with local user for subsequent Human Connect launches\\n}\\n\\n\\n/** Connect failure handler */\\n- (void)onConnectFailure:(NSString *)error\\n{\\n    NSLog(@\\\"Connect failure: %@\\\", error);\\n}\",\n      \"language\": \"java\",\n      \"name\": \"Objective-C\"\n    }\n  ]\n}\n[/block]\nThat's it! Now that you have the user's `humanId` and `accessToken`, you can start querying their data on your server for display in your app.\n\nSee the documentation in the [Data Retrieval](doc:data-overview) section of the documentation for more information.","excerpt":"How to use Human API to get health data easily from your mobile app","slug":"mobile-guide-ios","type":"basic","title":"iOS Guide"}

iOS Guide

How to use Human API to get health data easily from your mobile app

This page will help you get started with Human API for iOS. You'll be up and running in no time! If you haven't already, please create a developer account as described on the [Start Here](doc:start-here) page and come back here when you're done. #Overview There are two main parts to integrating Human API with your application: * **A:** Allowing your users to authenticate their data * **B:** Accessing authenticated user data This guide will walk through the implementation of the Human API iOS SDK to handle **part A** by allowing your users to authenticate their data within your application via the Human Connect popup . After the authentication process is complete, you will have the credentials needed to access user data from your server to complete **part B** as detailed in the [Data Retrieval](doc:data-overview) section of the documentation. [block:image] { "images": [ { "image": [ "https://files.readme.io/f0A9h1fgTeynYJsK1OXm_kannnect-ios.png", "kannnect-ios.png", "897", "1518", "#5cb9ac", "" ], "caption": "Connect on iOS", "sizing": "smart" } ] } [/block] [block:api-header] { "type": "basic", "title": "Add the SDK to your Application" } [/block] Copy the `HumanAPI` folder from [the master branch of the iOS SDK](https://github.com/humanapi/humanapi-ios-client/) and place it in the base level of your project directory. [block:api-header] { "type": "basic", "title": "Configure and Launch Human Connect" } [/block] Now that you have the SDK, it's time to set up the authentication flow. A user authenticates Human API by clicking the Connect Health Data button and authenticating their data directly with your application via Human Connect. [block:image] { "images": [ { "image": [ "https://files.readme.io/Ux0rUeXTRoup2PJ7oY4L_blue.png", "blue.png", "259", "49", "#4184c4", "" ] } ] } [/block] You can easily embed this authentication process directly into your iOS application. First, add the button above (or another button of your choosing) as a `UIButton` to the view you would like to launch Connect from and link it to an `IBAction` in the view controller. You can then use this button to launch Human Connect in the following three steps: #1. Import the SDK ViewController and Protocol In your ViewController.h file: * `#import "HumanConnectViewController.h"` at the top * Add `<HumanAPINotifications>` protocol to the ViewController e.g. `@interface ViewController : UIViewController <HumanAPINotifications>` #2. Instantiate the HumanConnectViewController Within the IBAction function you created, instantiate the `HumanConnectViewController`: [block:code] { "codes": [ { "code": "NSString *myClientID = @\"<Your-Client-ID>\";\nNSString *authURL = @\"http://localhost:3000/sessionToken\";\n \n \nHumanConnectViewController *hcvc = [[HumanConnectViewController alloc] initWithClientID:myClientID andAuthURL:authURL];\n \nhcvc.delegate = self;\n[self presentViewController:hcvc animated:YES completion:nil];", "language": "objectivec" }, { "code": "let clientId : String = \"659e9bd58ec4ee7fa01bc6b4627cb37e5c13ec21\"\nlet authURL : String = \"http://localhost:3000/sessionToken\"\n\n\nlet hcvc : HumanConnectViewController = HumanConnectViewController(clientID: clientId, andAuthURL: authURL);\n\nhcvc.delegate = self;\n\nself.presentViewController(hcvc, animated: true, completion: nil);", "language": "swift" } ] } [/block] You will need to pass these two values into the constructor: [block:parameters] { "data": { "h-0": "Name", "h-1": "Description", "0-0": "`clientId`", "1-0": "`authURL`", "0-1": "Unique ID of your developer portal application (found on the application settings page).", "1-1": "Custom endpoint on your server to handle the user token exchange.\n(You can add the default for now, we'll be implementing this in the second half of this guide.)" }, "cols": 2, "rows": 2 } [/block] #3. Launch Connect for the User Use `startConnectFlowForNewUser: (NSString *)userId` to launch Connect for a new user and pass it the unique ID of the user in your system (This will be returned in the final step so that you can associate Human API credentials with the correct user.) For now, this is all you need, but be aware that the next time the user launches Connect, you will need to use `startConnectFlowFor: (NSString *)userId andPublicToken: (NSString *)publicToken`. You will get this token after the first successful authentication. [block:code] { "codes": [ { "code": "[hcvc startConnectFlowForNewUser:locaUser.email];\n \n//If you have a publicToken for the user, supply it to Human Connect on launch\n//[hcvc startConnectFlowFor:localUser.email andPublicToken:localUser.publicToken];\n", "language": "objectivec" }, { "code": "hcvc.startConnectFlowForNewUser(localUser.email);\n \n//If you have a publicToken for the user, supply it to Human Connect on launch\n// hcvc.startConnectFlowFor(\"localUser.email\", andPublicToken: \"localUser.publicToken\")", "language": "swift" } ] } [/block] [block:callout] { "type": "warning", "title": "PublicToken", "body": "You will receive a `publicToken` at the end of the user authentication process. This value must be passed into Human Connect every time the user opens the popup thereafter. It is not necessary for the first launch." } [/block] #Complete Launch Implementation Altogether, your launch code for Human Connect should now look something like this: [block:code] { "codes": [ { "code": "/* ViewController.h */\n\n#import <UIKit/UIKit.h>\n#import \"HumanConnectViewController.h\"\n\n\n@interface ViewController : UIViewController <HumanAPINotifications>\n\n\n@end", "language": "objectivec" } ] } [/block] [block:code] { "codes": [ { "code": "/* ViewController.m */\n\n#import \"ViewController.h\"\n\n@interface ViewController ()\n\n@end\n\n@implementation ViewController\n\n- (void)viewDidLoad {\n [super viewDidLoad];\n // Do any additional setup after loading the view, typically from a nib.\n}\n\n- (void)didReceiveMemoryWarning {\n [super didReceiveMemoryWarning];\n // Dispose of any resources that can be recreated.\n}\n\n- (IBAction)launchHumanConnect:(id)sender {\n \n NSString *myClientID = @\"<Your-Client-ID>\";\n NSString *authURL = @\"http://localhost:3000/sessionToken\";\n \n \n HumanConnectViewController *hcvc = [[HumanConnectViewController alloc] initWithClientID:myClientID andAuthURL:authURL];\n \n hcvc.delegate = self;\n [self presentViewController:hcvc animated:YES completion:nil];\n \n\n [hcvc startConnectFlowForNewUser:locaUser.email];\n\n //If you have a publicToken for the user, supply it to Human Connect on launch\n //[hcvc startConnectFlowFor: localUser.email\n // andPublicToken: localUser.publicToken];\n \n}\n\n@end", "language": "objectivec" }, { "code": "import UIKit\n\nclass ViewController: UIViewController, HumanAPINotifications {\n\n override func viewDidLoad() {\n super.viewDidLoad()\n }\n\n override func didReceiveMemoryWarning() {\n super.didReceiveMemoryWarning()\n }\n\n @IBAction func launchConnect(sender: UIButton) {\n let clientId : String = \"<Your-Client-ID>\"\n let authURL : String = \"http://localhost:3000/sessionToken\"\n \n let hcvc : HumanConnectViewController = HumanConnectViewController(clientID: clientId, andAuthURL: authURL);\n \n hcvc.delegate = self;\n self.presentViewController(hcvc, animated: true, completion: nil);\n \n //Use your local user identifier here\n hcvc.startConnectFlowForNewUser(\"localUser.email\");\n\n\t\t\t //If you have a publicToken for the user, supply it to Human Connect on launch\n \t\t// hcvc.startConnectFlowFor(\"localUser.email\", andPublicToken: \"localUser.publicToken\")\n\n }\n\n}\n\n", "language": "swift" } ] } [/block] [block:callout] { "type": "warning", "title": "iOS 9+", "body": "If your authURL does not have SSL (https) such as the localhost example above, you will need to configure an App Transport Security Exception so that iOS does not block the POST request to an insecure URL. See the guide [here](http://ste.vn/2015/06/10/configuring-app-transport-security-ios-9-osx-10-11/) for more information." } [/block] That is all that is needed to correctly launch Human Connect to allow your users to authenticate their data. The second half of the authentication process will occur on your server at the `authURL` endpoint. [block:api-header] { "type": "basic", "title": "[Server-Side] Handle Token Exchange" } [/block] When a user authenticates a new data source in Human Connect, the Connect SDK will POST a `sessionTokenObject` to your server for final processing via the `authURL` specified on launch. To complete the token exchange process, you should: 1. Add your `clientSecret` to the `sessionTokenObject` (clientSecret can be found on the app settings page in the developer portal) 2. POST the modified `sessionTokenObject` from your server to Human API Tokens Endpoint: [block:code] { "codes": [ { "code": " https://user.humanapi.co/v1/connect/tokens", "language": "curl" } ] } [/block] 3. Retrieve and store `humanId`, `accessToken` and `publicToken` on your server with the user model to be used to query user data from Human API. ([See here](http://hub.humanapi.co/docs/overview-of-human-connect#key-data-points) for more information on what these values are.) 4. Return status `200` or `201` with payload containing `publicToken` to store on device for future launches of Human Connect: [block:code] { "codes": [ { "code": " { publicToken: \"2767d6oea95f4c3db8e8f3d0a1238302\" }", "language": "javascript" } ] } [/block] Here's an example of what this endpoint might look like in Node.js: [block:code] { "codes": [ { "code": "//Endpoint for specified 'authURL'\napp.post('/sessionToken', function(req, res, next) {\n\n var sessionTokenObject = req.body;\n // grab client secret from app settings page and `sign` `sessionTokenObject` with it.\n sessionTokenObject.clientSecret = '<Your-Client-Secret>';\n\n request({\n method: 'POST',\n uri: 'https://user.humanapi.co/v1/connect/tokens',\n json: sessionTokenObject\n }, function(err, resp, body) {\n if(err) return res.send(422);\n\n //Use these values to determine which user launched Connect\n console.log(\"clientId =\"+ body.clientId);\n console.log(\"clientId =\"+ body.clientId);\n\n /* Human API credentials. \n Save these with the user model in your system. */\n console.log(\"humanId = \" + body.humanId);\n console.log(\"accessToken = \"+ body.accessToken);\n console.log(\"publicToken = \"+ body.publicToken);\n\n\n //Send back publicToken to Android app\n var responseJSON = {publicToken: body.publicToken};\n\n res.setHeader('Content-Type', 'application/json');\n res.status(201).send(JSON.stringify(responseJSON));\n });\n});", "language": "javascript" } ] } [/block] For more information on the server implementation, see [Finalizing User Authentication](http://hub.humanapi.co/docs/integrating-human-connect#finalize-the-user-authentication). [block:api-header] { "type": "basic", "title": "Handle Callbacks from Human Connect" } [/block] When the token exchange process is complete on your server, the Human API SDK will deliver your response to the `(void) onConnectSuccess: (NSDictionary *)data` & `(void) onConnectFailure:(NSString *)error` callbacks on the user's device. #onConnectSuccess Here, you should save the returned `publicToken` on the device so that you can supply it to the HumanConnectViewController whenever the user launches Connect again in the future. #onConnectFailure This is called when there is an error from Connect. Implementation of this callback is this therefore optional. [block:code] { "codes": [ { "code": "/** Connect success handler */\n- (void)onConnectSuccess:(NSDictionary *)data\n{\n NSLog(@\"Connect success! publicToken=\\n %@\", data);\n \n //Notify user of success\n //Save publicToken with local user for subsequent Human Connect launches\n}\n\n\n/** Connect failure handler */\n- (void)onConnectFailure:(NSString *)error\n{\n NSLog(@\"Connect failure: %@\", error);\n}", "language": "java", "name": "Objective-C" } ] } [/block] That's it! Now that you have the user's `humanId` and `accessToken`, you can start querying their data on your server for display in your app. See the documentation in the [Data Retrieval](doc:data-overview) section of the documentation for more information.