Hi everyone,
I’m going to implement feature send email with gmail in backend server side. My idea is using Forge Provider with Google, I will use access_token and refresh_token which stored after user process login in Forge UI. But for now I can’t get access_token and refresh_token after flow auth done. Is anyway to get those token and any solution for my case ? I also check about send email with app password but I think using access_token is better way. Thanks for support me.
@HaiNguyen1,
For safety and security, Forge does not provide direct access to tokens. Instead, you use the api
library to manage access, and it will automatically handle the token flows, including adding the authorization header. Here’s some short psuedo-code as example:
import api from '@forge/api';
const google = api.asUser().withProvider('google', 'google-apis');
const response = await google.fetch('/userinfo/v2/me'); // Not node-fetch
When making the fetch()
request, the Forge API library will apply the token it has (which is why real-world examples also have a bit more token management logic). For more details, see the tutorial on how to use external fetch with OAuth 2.0.
1 Like