BlackBerry ID is one of the identity providers that you can integrate in your application.
If your app interacts with an off-device service that requires user authentication (for example, a website that requires the user to sign in with a username and password), you can use BlackBerry ID APIs to perform the off-device authentication/authorization using tokens, instead of prompting the user for credentials. Your app and the off-device service interact seamlessly.
The ids_get_properties function can be used to retrieve personal information stored in the BlackBerry ID account system, with BBID_PROPERTY_CORE passed as the type parameter (see code samples below).
In order to use BlackBerry ID as the identity provider for your app, you need to use the IDS APIs defined in the ids.h library.
Once these steps have completed successfully, the app can use the IDS APIs to store and retrieve data off the device, retrieve the user's personal information associated with their BlackBerry ID account, and use tokens for authentication and authorization.
This code sample shows how to initialize the IDS library:
// Make sure to include the following header files in your application
#include <errno.h>
#include <bps/bps.h>
#include <ids.h>
#include <ids_blackberry_id.h>
// Step 1 - Initialize IDS.
ids_result_t result = ids_initialize();
if( result != IDS_SUCCESS ) {
displayText( "Failure to initialize. errno: %d", errno );
return;
}
// Step 2 - Register to use BlackBerry ID as an identity provider.
static ids_provider_t* ids_provider;
static int ids_fd = -1;
result = ids_register_provider( BLACKBERRY_ID_PROVIDER,
&ids_provider,
&ids_fd );
if( result != IDS_SUCCESS ) {
displayText( "Failure to register. errno: %d", errno );
return;
}
// Step 3 - Add an FD handler for the IDS library communications.
if( bps_add_fd( ids_fd, BPS_IO_INPUT, &ids_io_handler,
NULL ) != BPS_SUCCESS ) {
displayText( "Failure to monitor fd. errno: %d", errno );
return;
}
After these three steps are complete and return successfully, your app is ready to use the IDS APIs to access functionality for BlackBerry ID as an identity provider.
Here's a code sample for how to access a user's email address, stored in the "username" field.
const char* properties[] = { IDS_BBID_PROP_USERNAME };
// Other valid values include IDS_BBID_PROP_SCREENNAME,
// IDS_BBID_PROP_FIRSTNAME, IDS_BBID_PROP_LASTNAME,
// and IDS_BBID_PROP_UID
result = ids_get_properties( ids_provider, BBID_PROPERTY_CORE, 1,
properties, handle_properties,
ids_call_failed, "get properties",
&request_id );
if( result != IDS_SUCCESS ) {
displayText( "Failure to getProperty. errno: %d", errno );
return;
}