Accessing Forge Storage from a Connect backend

We’re currently using Atlassian Connect Spring Boot (ACSB) for our app and are planning to migrate to Forge incrementally. With the release of ACSB version 4.1.0, Connect backends can now authenticate Forge requests. Is it possible to access Forge Storage from a Connect backend that also supports Forge requests? If yes, a sample code would be appreciated.

Hi @Berkayztrk,

Thanks for your interest. At the moment your app needs to be in the context of handling a request initiated by Forge in order to make authenticated requests back to the Forge storage api (and other api.atlassian.com APIs). If your app can work within this constraint, then yes, you will be able to access Forge storage via the GraphQL API as outlined here. Does that documentation provide sufficient information or are you after some sample code for making the GraphQL request from ACSB?

If your app needs to make Forge Storage requests other than when handling requests from Forge, you may need to wait for a future release; in what circumstances would your app be accessing Forge storage?

Cheers,
James Hazelwood
Engineer, Ecosystem
Atlassian

3 Likes

Thank you for the response.

I want to calculate some data on the backend for the authenticated user and store that data in Forge Storage. I am trying to figure out how to access Forge’s asApp and asUser JWTs in order to send GraphQL requests to Forge Storage. From the code, it appears that ACSB authenticates Forge requests and puts a ForgeApiContext object, wrapped by a ForgeAuthentication object, into the SecurityContext. All the information I need is in the ForgeApiContext object, but I can’t access these Forge-related classes from my app. I think they are currently internal classes.

Hey @Berkayztrk,

Does this occur once a user completes an action within your app (i.e. they press a button in Jira), or is this an offline activity?

You’ll have to ensure that you invoke a Forge Remote request to attain access to that token. At the moment, it will only exist within the context of the request, however there is a subsequent milestone which explores always available offline access to Forge remote - this would however only be asApp for now.

1 Like

Hi @SeanBourke,

Does this occur once a user completes an action within your app (i.e. they press a button in Jira), or is this an offline activity?

This occurs when a user takes action, not during offline activities.

You’ll have to ensure that you invoke a Forge Remote request to attain access to that token. At the moment, it will only exist within the context of the request, however there is a subsequent milestone which explores always available offline access to Forge remote - this would however only be asApp for now.

I invoke Forge Remote requests but cannot access Forge’s asApp and asUser JWTs within the ACSB backend. ACSB authenticates my Forge Remote requests and puts those JWTs into SecurityContext, wrapping them with the ForgeApiContext class. However, ForgeApiContext is an internal class, so I cannot use it. For now, I see two options: I can handle the Authorization header of incoming Forge Remote requests myself, or I can get the asApp/asUser JWTs with reflection from SecurityContext. I don’t want to use either method. I think ACSB should provide a way to access Forge API context data.

Hi @Berkayztrk

Thanks for reporting this issue in detail. We are currently working on a resolution to expose those classes so you can cast the SecurityContext details object to the correct class, and will have an update for you soon.

4 Likes

Hi @Berkayztrk

We have now released ACSB version 5.1.0, which allows you to use the ForgeContextRetriever to retrieve the Forge Invocation Token from within your ACSB app.

We have also shared a sample app detailing how to use it to make authenticated API calls back to Forge Storage.

Please let us know if you require any further assistance or have any feedback.

4 Likes

This topic was automatically closed after 30 days. New replies are no longer allowed.