LinkedIn Marketing API OAuth refresh fails in headless CI pipeline
0 reputation · 18 Jan 2023, 02:31 UTC
0 reputation · 18 Jan 2023, 02:31 UTC
Goal: maintain repeatable LinkedIn Marketing API OAuth 2.0 authentication in a CI/CD pipeline using access and refresh tokens instead of repeated interactive logins.
Uncertainty: refresh-token flow succeeds in interactive sessions but may fail in headless pipelines when LinkedIn session cookies are not preserved. The exact rejection response varies by API version. Marketing API v2 campaign-management calls also require the r_rlp scope; a missing scope returns 403 Forbidden, while revoked access tokens return a 400-level invalid-credential error.
Questions:
35275 reputation · 18 Jan 2023, 10:36 UTC
Yes. The refresh-token endpoint works in headless CI without preserved session cookies. The call requires only client_id, client_secret, and refresh_token with grant_type=refresh_token; no browser session or user interaction is involved.
A rejected refresh token returns HTTP 400 with invalid_grant, whether the token is revoked, expired through inactivity, or used outside an interactive session. An expired access token returns HTTP 401 with invalid_token. Campaign-management calls made without the r_rlp scope return HTTP 403 Forbidden.
| Item | Status | Notes |
|---|---|---|
| Refresh grant needs no cookies | Confirmed | OAuth 2.0 refresh grant; client credentials only. |
| Rejected refresh token | Confirmed | HTTP 400 invalid_grant. |
| Expired access token | Confirmed | HTTP 401 invalid_token. |
| Missing r_rlp scope | Confirmed | HTTP 403 on campaign-management endpoints. |
| Refresh-token rotation | Unverified | Check current LinkedIn docs; do not assume a new refresh token is issued. |
| Exact scope set per endpoint | Unverified | Some organization endpoints may require r_organization_admin. |
curl -X POST https://www.linkedin.com/oauth/v2/accessToken \
-d grant_type=refresh_token \
-d refresh_token="$LINKEDIN_REFRESH_TOKEN" \
-d client_id="$LINKEDIN_CLIENT_ID" \
-d client_secret="$LINKEDIN_CLIENT_SECRET"
Log the raw JSON and confirm a new access_token is present. Compare the scope value against r_rlp before calling campaign-management endpoints. Verify current error codes and token lifetimes in LinkedIn's developer docs before production use.
What HTTP status and error code does the pipeline currently receive when refresh fails? A 400 invalid_grant means the refresh token itself is invalid and requires re-authorization; a 401 invalid_token means only the access token expired and a refresh should succeed.
Use comments to ask for clarification. Post a solution as an answer.
5,790 reputation · 18 Jan 2023, 10:54 UTC
The OAuth 2.0 refresh token grant flow is inherently designed to operate without active user sessions or preserved session cookies. Successful execution depends only on the client credentials (ID/Secret) and the refresh token itself.
invalid_grant, rather than a session-related failure.