OAuth Integrations
Applications hosted on Posit Connect can be configured to use the content viewer’s OAuth access token, allowing publishers to author content that has access to third-party protected resources. This feature makes it possible for the content to user the viewer’s credentials when accessing protected resources, providing the viewer with a personalized view of the content. Access controls for protected resources are defined externally, allowing data administrators to reuse their organization’s existing data access policies and procedures. In Connect, viewers only see the data they have been granted access to in the third-party system.
OAuth integrations are only supported for interactive content types. Static and rendered content do not support OAuth integrations.
Content with access type Anyone - no login required is not supported.
For more information on configuring OAuth integrations in Connect, see the OAuth Integrations section of the Admin Guide.
Adding OAuth integrations to deployed content
Once the content has been deployed to Connect, the publisher associates the OAuth integration with their content.
This is accomplished using the dashboard by visiting the Access tab in the Content Settings pane, where the publisher will see an Integrations section with an Add integration button.
Clicking this button will open a modal which allows the Connect publisher to select an OAuth integration.
After selecting an integration and saving, the Add integration button is replaced with a panel containing information about the integration and a button to log in to the OAuth Integration.
Alternatively, the example below uses curl
and the Connect Server API to associate an OAuth integration with an existing piece of deployed content in Connect.
Replace connect.example.org
with the address of the Connect server.
Terminal
# list all available oauth integrations
curl -H "Authorization: Key ${CONNECT_API_KEY}" \
-XGET https://connect.example.org/__api__/v1/oauth/integrations
# assign an oauth integration to a piece of content
curl -H "Authorization: Key ${CONNECT_API_KEY}" \
-XPUT https://connect.example.org/__api__/v1/content/<content-guid>/oauth/integrations/associations \
--data '[
{"oauth_integration_guid": "<oauth-integration-guid>"}
]'
Viewing content on Connect
Connect users who have the Viewer permission on the content item receive a personalized view when they visit the deployed application.
Upon visiting a piece of content that is associated with an OAuth integration for the first time, if the user is accessing the content through the Connect dashboard, they are prompted to login to the OAuth integration.
The login modal only appears if the user is not already logged in and the content settings pane is closed. The Login button is also available on the Access tab of the Content Settings pane.
When interacting with the content in open-solo mode and the viewer is not already logged in, then the viewer is automatically redirected to the login URL of the OAuth integration in order to initialize their OAuth session.
OAuth sessions
An OAuth session holds metadata about the Connect user’s OAuth tokens. An OAuth session is created when a Connect user visits the /login
endpoint of any OAuth integration. The login endpoint has the form: /__oauth__/integrations/<oauth-integration-guid>/login
. In order to populate the OAuth session with an access token and refresh token, the user must complete the login flow by visiting the /login
endpoint and successfully authenticating to the external service. After authenticating to the external service, the user is redirected back to Connect.
The user’s OAuth session and all OAuth tokens are deleted when the Connect user visits the /logout
endpoint. The logout endpoint has the form: /__oauth__/integrations/<oauth-integration-guid>/logout
.
OAuth sessions can also be managed using the /v1/oauth/sessions
API endpoints. By default, Connect users can only manage their own OAuth sessions. Connect administrators can manage OAuth sessions of all Connect users. Managing an OAuth session does not allow the user to view OAuth tokens associated with the OAuth session. Access tokens are exposed only by the credential exchange endpoint. OAuth refresh tokens are never returned by Connect.
An authenticated user in Connect can have only one OAuth session per OAuth integration. A given OAuth integration can be shared by multiple content items on Connect. The user only needs to login to the OAuth integration once and the OAuth session remains valid for all pieces of content that use that OAuth integration. A user is considered to be logged in to the OAuth integration if there is an OAuth refresh token associated with the OAuth session.
A content viewer must visit a piece of content in order for the content to obtain the viewer’s access token. Simply associating an OAuth integration with a piece of content is not enough for the content to obtain the user’s access token.
This limitation prevents a content item from obtaining an arbitrary user’s access token, even when that user is assigned the Viewer role on the content. See the security documentation for additional details.