Basic#
The simplest way to authenticate with the AcceleratXR backend is using Basic authentication via the /auth/password
REST API endpoint or via one of the Login() functions in CoreSDK. This endpoint supports authentication using
an account’s stored password, api key or device.
The below example shows how to authenticate using this method using a user’s unique name and password:
1CoreSDK->LoginPassword(_XPLATSTR("username"), _XPLATSTR("password"))
2 .then([](pplx::task<void> task)
3{
4 try
5 {
6 // Force the exception to be re-thrown if an error occurred.
7 task.get();
8 }
9 catch (const xbe::sdk::Exception& e)
10 {
11 // Handle error here
12 }
13});
1try
2{
3 await CoreSDK.LoginPassword("username", "password");
4}
5catch (Exception error)
6{
7 // Handle error here
8}
1try
2{
3 await CoreSDK.loginPassword("username", "password");
4}
5catch (error: any)
6{
7 // Handle error here
8}
1try
2{
3 AXRCoreSDK SDK = AXRCoreSDK.GetInstance();
4 await SDK.Instance.LoginPassword("username", "password");
5}
6catch (Exception error)
7{
8 Debug.LogError("Failed device login. Error=" + error.Message);
9}
1FOnlineSubsystemXBE* OSS = (FOnlineSubsystemXBE*)(IOnlineSubsystem::Get(XBE_SUBSYSTEM));
2check(OnlineSub != nullptr);
3const IOnlineIdentityPtr IdentityInterface = OnlineSub->GetIdentityInterface();
4check(IdentityInterface.IsValid());
5
6FDelegateHandle LoginDelegateHandler;
7auto LoginDelegate = FOnLoginCompleteDelegate::CreateLambda([=](
8 int32 InLocalUserNum,
9 bool bWasSuccessful,
10 const FUniqueNetId& UserId,
11 const FString& Error)
12{
13 if (Error.Len() > 0)
14 {
15 // Handle error here
16 }
17
18 IdentityInterface->ClearOnLoginCompleteDelegate_Handle(
19 InLocalUserNum,
20 LoginDelegateHandler);
21});
22
23LoginDelegateHandler = IdentityInterface->AddOnLoginCompleteDelegate_Handle(0, LoginDelegate);
24
25FOnlineAccountCredentials creds;
26creds.Type = ELoginMethods::ToString(ELoginMethods::Basic);
27creds.Id = TEXT("username");
28creds.Token = TEXT("password");
29IdentityInterface->Login(0, creds);
1GET /auth/password HTTP/1.1
2Authorization: Basic BASE64("username:password")
A successful authentication request will return a valid access token and cookie, or return without an error when using the SDK. Access tokens are typically valid for one hour before they must be refreshed.
Multi-factor Challenge#
For users that have enabled multi-factor authentication on their account they may be prompted to enter a time-based
one-time password (TOTP) code to retrieve the final access token. The system notifies the user of this requirement
by returning a CHALLENGE token after the initial request succeeds. The user then must follow up the initial
request with a call to the /auth/totp endpoint or by using the CoreSDK.LoginTotp() function in the SDK.
When calling the the TOTP endpoint the challenge token must be provided in addition to the TOTP code as generated by the user’s registered authenticator app or device:
1CoreSDK->SetTotpChallengeCallback(CoreSDK->CreateTask([]()
2{
3 utility::string_t code;
4 // TODO Prompt user to enter TOTP code
5 return code;
6}));
7
8CoreSDK->LoginPassword(_XPLATSTR("username"), _XPLATSTR("password"))
9 .then([](pplx::task<void> task)
10{
11 try
12 {
13 // Force the exception to be re-thrown if an error occurred.
14 task.get();
15 }
16 catch (const xbe::sdk::Exception& e)
17 {
18 // Handle error here
19 }
20});
1try
2{
3 await CoreSDK.LoginPassword("username", "password");
4}
5catch (Exception error)
6{
7 // Handle error here
8}
1try
2{
3 CoreSDK.onAuthChallenge = async () => {
4 let code: string = "";
5
6 // TODO Prompt user to enter TOTP code
7 return code;
8 };
9
10 await CoreSDK.loginPassword("username", "password");
11}
12catch (error: any)
13{
14 // Handle error here
15}
1try
2{
3 AXRCoreSDK SDK = AXRCoreSDK.GetInstance();
4 await SDK.Instance.LoginPassword("username", "password");
5}
6catch (Exception error)
7{
8 Debug.LogError($"Failed device login. Error={error.Message}");
9}
1FOnlineSubsystemXBE* OSS = (FOnlineSubsystemXBE*)(IOnlineSubsystem::Get(XBE_SUBSYSTEM));
2check(OnlineSub != nullptr);
3const IOnlineIdentityPtr IdentityInterface = OnlineSub->GetIdentityInterface();
4check(IdentityInterface.IsValid());
5
6FDelegateHandle LoginDelegateHandler;
7auto LoginDelegate = FOnLoginCompleteDelegate::CreateLambda([=](
8 int32 InLocalUserNum,
9 bool bWasSuccessful,
10 const FUniqueNetId& UserId,
11 const FString& Error)
12{
13 if (Error.Len() > 0)
14 {
15 // Handle error here
16 }
17
18 IdentityInterface->ClearOnLoginCompleteDelegate_Handle(
19 InLocalUserNum, LoginDelegateHandler);
20});
21
22LoginDelegateHandler = IdentityInterface->AddOnLoginCompleteDelegate_Handle(
23 0, LoginDelegate);
24
25FOnlineAccountCredentials creds;
26creds.Type = ELoginMethods::ToString(ELoginMethods::Basic);
27creds.Id = TEXT("username");
28creds.Token = TEXT("password");
29IdentityInterface->Login(0, creds);
1POST /auth/totp HTTP/1.1
2Authorization: jwt CHALLENGE_TOKEN
3Content-Type: application/json
4Content-Length: ...
5
6{
7"totp": "{TOTP}",
8"userUid": "{UID}"
9}