I have carefully reviewed the Forge documentation and understand that user/app authentication tokens are accessible within Forge remote backends. However, I am seeking to access an authentication token directly within a resolver, thereby eliminating the need for an external backend solely for token retrieval. While I am aware that asApp()
and asUser()
suffice for making calls to product APIs without explicit authentication tokens, my objective is to obtain a bearer authentication token to call other Atlassian APIs. Is there a method to access such a bearer authentication token within a Forge app?
@Lucas Modzelewski _Lumo_ is correct — you can't extract the token used by `asApp()` or `asUser()`.
@ankit jangid may I ask which other Atlassian APIs you're attempting to call?
If the API does not support OAuth scopes, you can instead:
- generate a personal access token and set it as a Forge environment variable (use the `--encrypt` flag given it's a credential)
- override the `Authorization` header on the request to use the access token
However this will mean the app will authenticate with the API as the user you generated the access token for.
Please also note that this is also only suitable for apps that you're deploying for use in your own organisation. Our Security Requirements prohibit Marketplace Apps from soliciting API tokens from users.
Hope this helps!
Tim
@Tim Pettersen Thank you for the detailed response. I am currently developing a Forge app for Confluence that subscribes to the avi:confluence:created:comment
event. My goal is to automatically convert the Confluence page, where a comment containing a specific keyword was made, into a PDF and then upload that PDF as an attachment to the same page. This effectively creates a snapshot of the page.
I initially attempted to use standard Confluence APIs to retrieve the page content in HTML format. However, I encountered an issue where the HTML returned did not include the rendered content of macros, making it impossible to generate a complete and accurate PDF from that output.
As a workaround, I am now attempting to utilize the internal Confluence API: ${baseUrl}/spaces/flyingpdf/pdfpageexport.action?pageId=${pageId}
. This API is used by Confluence itself for PDF page exports and reliably captures all page content, including macros. To successfully invoke this specific internal API, I understand that a user bearer token is required.
While this approach successfully allows me to convert a Confluence page to PDF, it currently necessitates obtaining an authentication token directly from users, which is something I aim to avoid.
Could you please provide guidance on how I can obtain the complete Confluence page content, including all rendered macros, in HTML format via an official Confluence API? If I can access this comprehensive HTML, I can then generate the PDF programmatically, thereby eliminating the need for the internal flyingpdf
API and the requirement to solicit authentication tokens from users.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can’t directly access the user’s OAuth/JWT/bearer token in Forge resolvers (for security reasons) - that’s by design in the Forge platform.
The actual token is never exposed to your app code or frontend, so it can't be leaked or misused.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Note: When exporting a page with macros to PDF, not all macros are supported in PDF export - be sure to check if the ones you need have correct data in export.
Also check this discussion: https://community.developer.atlassian.com/t/retrieve-the-html-content-from-a-confluence-page-to-display-it-exactly-as-it-appears-in-confluence/81166
__
PS: If you ever get stuck with multiple attachments, I’ve built an app to help you remove attachments that aren’t used in the content: https://marketplace.atlassian.com/apps/1236523/attachments-cleanup-assistant?hosting=cloud&tab=overview
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.