-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Oauth support #850
Merged
Merged
Oauth support #850
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
const fetch = require('node-fetch'); | ||
const querystring = require('querystring'); | ||
|
||
const oauthRefreshRequestHandler = (req, res) => { | ||
const refreshUrl = req.params[0]; // TODO: get this from the tool somehow to prevent leaking secret to any supplied url | ||
const data = { | ||
'grant_type': 'refresh_token', | ||
'refresh_token': req.body.refresh_token, | ||
'client_id': req.body.client_id, | ||
'client_secret': req.body.client_secret, | ||
}; | ||
fetch(refreshUrl, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/x-www-form-urlencoded' | ||
}, | ||
body: querystring.stringify(data) | ||
}).then(response => { | ||
return response.json(); | ||
}).then(data => { | ||
res.send(data); | ||
}).catch(error => { | ||
res.send(error); | ||
}); | ||
}; | ||
|
||
const oauthAcquireRequestHandler = (req, res) => { | ||
const acquireUrl = req.params[0]; // TODO: get this from the addon somehow to prevent leaking secret to any client-supplied url (e.g. via postman) | ||
const data = { | ||
'grant_type': 'authorization_code', | ||
'code': req.body.code, | ||
'redirect_uri': req.body.redirect_uri, | ||
'client_id': req.body.client_id, | ||
'client_secret': req.body.client_secret, | ||
}; | ||
fetch(acquireUrl, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/x-www-form-urlencoded' | ||
}, | ||
body: querystring.stringify(data) | ||
}).then(response => { | ||
return response.json(); | ||
}).then(data => { | ||
res.send(data); | ||
}).catch(error => { | ||
res.send(error); | ||
}); | ||
}; | ||
|
||
module.exports = { | ||
oauthRefreshRequestHandler, | ||
oauthAcquireRequestHandler | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const https = require('https'); | ||
|
||
const proxyRequestHandler = (req, res) => { | ||
const input = req.params[0]; | ||
if (!input.includes('://')) { | ||
const proxyURL = `https://toolboxedge.net/${req.params[0]}`; | ||
const headers = req.headers; | ||
headers.Host = "toolboxedge.net"; | ||
https.get(proxyURL, {headers}, proxyRes => { | ||
for (let header in proxyRes.headers) { | ||
res.setHeader(header, proxyRes.headers[header]); | ||
} | ||
proxyRes.pipe(res); | ||
}); | ||
} else { | ||
const proxyURL = req.params[0]; | ||
const headers = req.headers; | ||
headers.Host = new URL(proxyURL).host; | ||
const queryParams = new URLSearchParams(req.query); | ||
const url = `${proxyURL}?${queryParams.toString()}`; | ||
https.get(url, {headers}, proxyRes => { | ||
for (let header in proxyRes.headers) { | ||
res.setHeader(header, proxyRes.headers[header]); | ||
} | ||
proxyRes.pipe(res); | ||
}); | ||
} | ||
}; | ||
|
||
module.exports = proxyRequestHandler; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is expected to always be an onshape url there could be an allowList of known urls to which we're okay with sending oauth requests. Any new developer of an oauth-enabled tool would then locally modify this allowList and eventually get us to ad the new domain to all edge servers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking of having the allowList be part of the secrets file for the add-on, since this is designed to be used with anything that supports OAuth, not just Onshape.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thumbs up emoji