Running a RAR flow in iOS
PingOne Advanced Identity Cloud PingAM iOS
In this tutorial you run a complete RAR payment transaction in the OidcExample sample app from the Orchestration SDK sample apps repository.
The app requests authorization for a specific payment, the user approves the payment details on the Remote Consent Service page, and the app displays the granted details from the token response.
Before you begin
Ensure that you have completed the following prerequisite tasks before attempting to run the sample app:
-
Step 2. Preparing the authorization server
The tutorial supports both PingOne Advanced Identity Cloud and PingAM.
PingOne Advanced Identity Cloud only: your tenant must run PingOne Advanced Identity Cloud version 23604.0 or later, or the authorization server issues an empty authorization_details grant.
If you test on the iOS simulator, install the mkcert root certificate into each simulator you test on:
xcrun simctl keychain booted add-root-cert "$(mkcert -CAROOT)/rootCA.pem"
The simulator does not inherit your Mac’s certificate trust settings. Without the certificate, the consent page fails with a "This Connection Is Not Private" error in the simulator, even though the same URL loads in your Mac’s browser.
Step 1. Downloading the sample app
In this step you download the Orchestration SDK sample apps repository containing the OidcExample sample app.
To download or clone a copy of the SDK Sample Apps repo, complete these steps:
-
In a web browser, navigate to https://github.com/ForgeRock/sdk-sample-apps.
-
Download the source code using one of the following methods:
- Download a ZIP file
-
-
Click Code, and then click Download ZIP.
Figure 1. Downloading a zip file of the sample apps repo. -
Extract the contents of the downloaded ZIP file to a suitable location.
-
- Use a Git-compatible tool to clone the repo locally
-
-
Click Code, and then copy the HTTPS URL.
Figure 2. Downloading the sample apps repo using Git clone. -
Use the URL to clone the repository to a suitable location.
For example, from the command-line you could run:
git clone https://github.com/ForgeRock/sdk-sample-apps.git
-
After completing these steps, you will have a local folder named sdk-sample-apps. Inside, you’ll find separate folders for the Android, iOS, JavaScript, and React Native sample app projects.
The sample app is in iOS/swiftui-oidc-module in the cloned repository.
Step 2. Configuring the sample app
In this step you set the connection properties for your RAR-enabled client in the sample’s source code, and register the redirect URI scheme in Xcode.
The sample authenticates as two OAuth 2.0 clients: a standard client for the plain login, and a dedicated RAR client for the RAR login. Configure both.
-
Open
iOS/swiftui-oidc-module/OidcExample.xcodeprojin Xcode. There is no workspace file for this sample. -
In
OidcExample/ViewModels/OidcLoginViewModel.swift, replace the editor placeholders inmakeOidcWebClient(overrides:)with your authentication OAuth 2.0 client values:oidcValue.clientId = "sdkPublicClient" (1) oidcValue.scopes = Set(["openid", "profile", "email", "address"]) (2) oidcValue.redirectUri = "com.example.demo://oauth2redirect" (3) oidcValue.discoveryEndpoint = "https://openam-forgerock-sdks.forgeblocks.com/am/oauth2/realms/alpha/.well-known/openid-configuration" (4)1 The client ID of the standard client you registered in Step 2. Preparing the authorization server. 2 The scopes registered on your clients, matching the scopes you set in Step 2. Preparing the authorization server. The scopesvalue must be aSet, not an array.3 The redirect URI registered on your standard client. For example, com.example.demo://oauth2redirect.4 The discovery endpoint of your PingOne Advanced Identity Cloud tenant or PingAM server. The example path uses the alpharealm; adjust the realm path if your client is in a different realm. -
In
OidcExample/Configuration/RarClientStore.swift, replace theRAR Client IDplaceholder with the client ID of your RAR-enabled client.For example,
rarClient, the client ID suggested in Step 2. Preparing the authorization server. -
Register the redirect URI scheme in Xcode:
-
Select the project in the Project Navigator.
-
Open the Info tab, and expand URL Types.
-
Add a URL scheme matching the scheme of your redirect URI.
For example, if your redirect URI is
com.example.demo://oauth2redirect, use the following values:-
URL Schemes: The scheme portion of your deep link, for example
com.example.demo. -
Identifier: The part of the redirect URI after the
://symbol, for exampleoauth2redirect.
-
-
Step 3. Building and running the sample app
In this step you build the sample and run it on a simulator or physical device.
-
In Xcode, build and run the
OidcExamplescheme on a simulator or a physical device.The app displays the main menu:
Figure 3. The OidcExample main menu -
Tap Launch OIDC Login, tap Start OIDC Login, and then authenticate as a demo user.
Tap Continue if the sample asks whether you want to open the browser to authenticate on your tenant.
-
After successfully authenticating, tap Back to return to the menu screen.
-
Tap Launch RAR Login.
The app displays the RAR Login page:
Figure 4. The RAR Login page -
Select the payment_initiation preset, or swipe across to the Custom option and enter your own authorization details JSON.
The preset requests a payment of 123.50 EUR to Merchant A:
Exampleauthorization_detailspreset requesting a payment of 123.50 EUR to Merchant A[ { "type": "payment_initiation", "locations": ["https://example.com/payments"], "instructedAmount": {"currency": "EUR", "amount": "123.50"}, "creditorName": "Merchant A", "creditorAccount": {"iban": "GB29MRCH60161331926819"}, "remittanceInformationUnstructured": "Ref Number Merchant" } ] -
Scroll to the bottom of the page and tap Login with authorization_details.
The app opens the browser, connects to your tenant, which redirects you to the local RCS server for your consent.
Figure 5. The Remote Consent Service consent page -
Review the payment details on the consent page, and then tap Approve:
The RCS returns its signed consent response, and the authorization server redirects back to the app with an authorization code.
-
Tap View RAR Access Token to check that the token response contains the authorization details you approved on the consent page.
Troubleshooting
Use the following troubleshooting advice if the sample does not work as expected.
| What you see | What it means |
|---|---|
Granted |
RAR processing ran, but the consent response carried no details. Either the RCS has no enricher for the requested type and dropped it, or the consent response did not echo the claim. |
No |
RAR processing never ran. Check the Rich Authorization Requests with Remote Consent Service provider toggle, and the tenant version on PingOne Advanced Identity Cloud. |
|
The requested type is not in the client’s Authorization Detail Type(s) list. |
|
The client has implied consent enabled, which is incompatible with RAR. Turn implied consent off. |
Consent page fails with a JWT signature error |
The Remote Consent Agent’s signing algorithm does not match the RCS. With the demonstration RCS, set the agent to HS256. |
"Unexpected number of Base64URL parts, must be three" |
Consent request encryption is enabled on the agent. Turn it off; the demonstration RCS reads signed, not encrypted, JWTs. |