User Token Management

Save and get the user token when you need it with the Apps Panel iOS SDK.

The iOS Apps Panel SDK provides a way to securely store the user token within your app, and to retrieve it when you need it.

Integration

There are no defined ways to get the user token from the back end. The usual way is to get as a response when the user logs into your app. Once you have made a call to get your user token from the web services, you can save it as follow:

#import "APUserTokenManager.h"

- (void)apwsFinishedDownload:(APWSManager *)apws {
	if (apws.tag == 1){
	NSDictionnary *user = apws.result;
  
  	if ([user objectForKey:@"token"]) { //Check if the token value exists
    		[[APUserTokenManager sharedInstance] saveToken:[user objectForKey:@"token"]];
    }
  }
}
//TODO

Once the token is saved, you just need to set needsToken to YES when you make a call that needs it:

- (void)getUserProfile:(User*)user {
  
	APWSManager *apws =  [[APWSManager alloc] initWithRest:@"user/profile" 
                        delegate:self 
												WithGet:nil 	
                        andTag:1000];
	
	[apws setNeedsToken:YES];
  
	[apws start];
}

If needed, you can retrieve the user token with the getTokenmethod of APUserTokenManager.

Finally, you have the possibility to delete the user token. You should call this method at least when the user logs out of your app.

[[APUserTokenManager sharedInstance] deleteToken];