Registration with third-party mobile application
Introduction
Registration with third-party mobile application is possible using two step custom registration.
Prerequisites
Number of properties needs to be setup on the backend side, so be sure that it is properly configured. Proper two step custom registration IDP with scripts for both init and complete steps needs to be set up. Third-party app needs to be installed on the device and be ready to receive and emit App Links.
Flow overview
title App2App actor User User->>APP: start registration APP->>SDK: registerUser() - custom two step registration SDK->>APP: initRegistration() callback APP->>SDK: initRegistration: callback.returnSuccess(null) SDK->>BACKEND: registration initialization request BACKEND->>SDK: json with AppLink SDK->>APP: finishRegistration(customInfo: json) callback APP->>APP: save sessionId from json APP->>EXTERNAL_APP: AppLink from json opens external app EXTERNAL_APP->>EXTERNAL_APP: Proceed with authentication EXTERNAL_APP->>APP: AppLink opens app with json holding artefectId APP->>SDK: finishRegistration: callback.returnSuccess(Json(artefactId, sessionId) SDK->>BACKEND: send finish registration request with json BACKEND->>SDK: finish registration success SDK->>APP: create PIN APP->>User: ask for new PIN User->>APP: provide PIN APP->>SDK: onPinProvided SDK->>SDK: store encrypted refreshToken SDK->>APP: registration success APP->>User: registered
- App initiates custom registration with
initrequest. Initresponse withsessionIdandapp link.- App opens the third party app using
app link. - Third party app authenticates user and navigates back to the app using
app link. - App extracts
artefactIdfrom theapp linkand sends it to the backend along withsessionId. - Registration finishes and app receives access/refresh token.
- Proceed with PIN creation flow.
Example of the flow
Your app needs to be able to receive App Links from third party app. Be sure to register correct app link in your manifest file.
Implement OneginiCustomTwoStepRegistrationAction interface.
public class App2AppRegistrationAction implements OneginiCustomTwoStepRegistrationAction {
public static OneginiCustomRegistrationCallback CALLBACK;
public App2AppRegistrationAction() {
}
@Override
public void initRegistration(final OneginiCustomRegistrationCallback callback, final CustomInfo customInfo) {
__ Init registration with null data
callback.returnSuccess(null);
}
@Override
public void finishRegistration(final OneginiCustomRegistrationCallback callback, final CustomInfo customInfo) {
__ Extract "sessionID" and "app link" from json.
JsonObject jsonObject = new JsonParser().parse(customInfo.getData()).getAsJsonObject();
__ Save sessionId - you will need it later.
String sessionId = jsonObject.get("sessionID").getAsString();
String appLink = jsonObject.get("thirdPartyAppLink").getAsString();
__Start third-party app
context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(appLink)));
}
}
On successful authentication in third-party app, it will run app link back into your app with json response. Unpack response value, parse it with sessionId into new json and send it back do the backend via callback.onSuccess(json) from finishRegistration method.
Implement OneginiCustomIdentityProvider interface.
public class App2AppIdentityProvider implements OneginiCustomIdentityProvider {
private final OneginiCustomTwoStepRegistrationAction registrationAction;
public App2AppIdentityProvider() {
this.registrationAction = new App2AppRegistrationAction();
}
@NonNull
@Override
public OneginiCustomRegistrationAction getRegistrationAction() {
return registrationAction;
}
@NonNull
@Override
public String getId() {
return "app2app";
}
}
In example above, IDP id is
app2app, be sure to use an id of the IDP which is set in your backend.
Add Custom Identity Provider
return new OneginiClientBuilder(applicationContext, createPinRequestHandler, pinAuthenticationRequestHandler)
...
.addCustomIdentityProvider(new App2AppIdentityProvider())
Implement Registration Handler
final OneginiRegistrationHandler registrationHandler = new OneginiRegistrationHandler() {
@Override
public void onSuccess(final UserProfile userProfile, final CustomInfo customInfo) {
__ Handle registration success
}
@Override
public void onError(@NonNull final OneginiRegistrationError oneginiRegistrationError) {
__ Handle registration error
}
};
Register user
oneginiClient.getUserClient().registerUser(identityProvider, registrationHandler);