Intent, and Android returns the person’s decision to your app.
The authorization activity is available in 1Password for Android 8.12.42 or later. See Supported builds.
How it works
- Your app puts the access request reference and the protocol version in an
Intentfor thecom.onepassword.android.workloadaccess.action.REQUEST_AUTHORIZATIONaction, addressed to the 1Password package. - Your app starts that
Intentfor a result, and 1Password opens a bottom sheet over your app. - 1Password shows the access request, unlocking first if needed, and the person grants or denies it. If 1Password can’t show or answer the request, the sheet tells the person why.
- Your app’s activity result callback receives either an access request status, which decodes to an
OnePasswordAccessGrant, or an error.
Get the access request reference
Create the access request first. The reference is the value 1Password reads to find the account and the request, including what you asked for and why. It’s theaccess_request_reference value in the appLink returned when you create the request, by the browser extension’s createAccessRequest or by the SDK’s accessRequests.create. If you create requests with the SDK, contact 1Password first.
Pass the reference unchanged. Don’t decode it, edit it, or build it from parts. Like the approval link, it carries your request text, so keep it out of logs and model context.
Add the integration types
1Password provides these Kotlin definitions. They usekotlinx.serialization to decode the grant. Add them to your app module:
The request
The request travels as twoIntent extras:
The access grant
The access grant is the access request’s status, read from 1Password after the person granted it, together with the protocol version it’s encoded in. It arrives as a JSON string in thecom.onepassword.android.workloadaccess.extra.ACCESS_REQUEST_STATUS extra:
payload carries the state and resolved fields that the SDK’s accessRequests.getStatus returns, except for reference: in the grant, each reference is an object that wraps the reference string, { "reference": "<string>" }, while getStatus returns the string itself. The grant doesn’t include the status path.
A later version of this protocol is expected to return each
reference as a plain string, the same as getStatus. 1Password always answers in the version you ask for, so your app keeps working until you move to the new version.Declare the 1Password package
Android 11 and later hide other apps from yours unless you declare which ones you interact with. Without this declaration, Android can’t find 1Password’s activity and launching the request fails. Add a<queries> element to your app’s AndroidManifest.xml:
AndroidManifest.xml
Send the access request
- Register
OnePasswordAccessRequestContractwithregisterForActivityResultin your activity or fragment, before it’s started. - Wrap the access request reference in an
OnePasswordAccessRequest. - Launch the request when the person is ready to review it.
startActivity instead, 1Password still shows the sheet, but your app never learns the person’s decision.
Handle the result
Android calls your activity result callback when the sheet closes. WhatOnePasswordAccessRequestContract returns depends on how the request ended:
When 1Password can’t show or answer the access request, the sheet tells the person why, and offers to try again when that can help. This includes a request with a missing or malformed extra. Your app gets the
error result when the person closes that message, not straight away.
Cancelled means the access request is still pending, so the person can answer it later. The person can’t close the sheet while 1Password sends their answer.
Decode the access grant
Decode the access request status as anOnePasswordAccessGrant. Ignore keys you don’t recognize, because a later release may add optional fields without changing the protocol version:
Use the grant
Eachreference in the grant identifies one granted login. It holds no secret, and it works only with the access token and integration key of the connection that created the request, which stay on your side. The extension and the SDK both take the string inside it, reference.reference, not the object:
- To fill in your agent’s browser: pass
reference.referenceto the extension’sfillCredentialasresourcePath, with the same connection’s access token and integration key. - To read the login with the SDK: pass
reference.referenceto the SDK’s read methods. See Read a granted login.
Errors
If 1Password can’t process the request, the result carries an error code in thecom.onepassword.android.workloadaccess.extra.ERROR extra. These are the codes 1Password reports today, the cases of OnePasswordAccessRequestError:
Treat any other code, or a
Failed result with a null error, as a failed access request. 1Password may add error codes.
Unlike on iOS, a denial isn’t an error. When the person denies the request, you get Denied. Don’t retry automatically after Denied or Cancelled.
Open an access request link instead
If your app can’t start an activity for a result, for example because it runs in a browser, open the access request link instead, and add areturn_url query parameter to it. 1Password opens return_url when the access request ends, which brings the person back to your app:
return_url is the only change you make to the link. Keep everything else as you got it.
return_url can be an App Link or a URL scheme your app handles. During the partner preview, 1Password opens any return_url the link carries. A later release opens only the return URLs registered for your OAuth client, so tell your 1Password contact which ones you use.
1Password adds the outcome to return_url as query parameters, and keeps any parameters your URL already has:
<code> is one of the error codes above, except internal_error, because an error that leaves the access request pending doesn’t end it. The parameters never carry credentials, so read what the person granted with the SDK’s accessRequests.getStatus.
1Password doesn’t open return_url when the person closes the sheet without answering, because the access request is still pending and they can answer it later. A link without return_url still works: when the request ends, 1Password closes the sheet, and Android shows the app the person was in before.
If the person opens the link with no account signed in to 1Password, the sheet offers to sign in, and your app gets account_not_found. 1Password doesn’t hold on to the link while the person signs in, so they open it again afterward.
An app that starts the request for a result, as in Send the access request, isn’t sent to return_url. It gets the outcome as the activity result.