Skip to content

Commit

Permalink
Merge pull request #59 from gofynd/enhancement/path-redirection
Browse files Browse the repository at this point in the history
Enhancement/path redirection
  • Loading branch information
brijeshgajjarfynd authored Jul 29, 2024
2 parents 4516d68 + 2a7560b commit c58df22
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [v0.7.7] - 2024-07-19
### Changed
- Handle refresh token not working for token which has expiry as `null`.
- Added support for passing `redirect_path` as a query paramater to the launch url of the extension.
---
## [v0.7.6] - 2024-07-11
### Changed
Expand Down
5 changes: 5 additions & 0 deletions express/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ function setupRoutes(ext) {
let companyId = parseInt(req.query.company_id);
let platformConfig = await ext.getPlatformConfig(companyId);
let session;
let redirectPath = req.query.redirect_path;

session = new Session(Session.generateSessionId(true));

Expand All @@ -33,6 +34,7 @@ function setupRoutes(ext) {
session.expires = sessionExpires;
session.access_mode = 'online'; // Always generate online mode token for extension launch
session.extension_id = ext.api_key;
session.redirect_path = redirectPath;
} else {
if (session.expires) {
session.expires = new Date(session.expires);
Expand Down Expand Up @@ -146,6 +148,9 @@ function setupRoutes(ext) {
});
}
let redirectUrl = await ext.callbacks.auth(req);
if(req.fdkSession.redirect_path){
redirectUrl = req.fdkSession.redirect_path;
}
logger.debug(`Redirecting after auth callback to url: ${redirectUrl}`);
res.redirect(redirectUrl);
} catch (error) {
Expand Down
4 changes: 3 additions & 1 deletion express/session/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Session {
this.refresh_token = null;
this.isNew = isNew;
this.extension_id = null;
this.redirect_path = null;
}

static cloneSession(id, session, isNew=true) {
Expand All @@ -39,7 +40,8 @@ class Session {
refresh_token: this.refresh_token,
expires_in: this.expires_in,
extension_id: this.extension_id,
access_token_validity: this.access_token_validity
access_token_validity: this.access_token_validity,
redirect_path: this.redirect_path
};
}

Expand Down

0 comments on commit c58df22

Please sign in to comment.