Skip to content
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

Add token exchange #110

Merged
merged 3 commits into from May 8, 2020
Merged

Add token exchange #110

merged 3 commits into from May 8, 2020

Conversation

kpuputti
Copy link
Contributor

@kpuputti kpuputti commented May 6, 2020

Add a new method sdk.exchangeToken() that reads the current access
token, and uses that together with the configured client secret to
exchange the auth token into another token for privileged transitions.

Add a new method `sdk.exchangeToken()` that reads the current access
token, and uses that together with the configured client secret to
exchange the auth token into another token for privileged transitions.
src/sdk.js Show resolved Hide resolved
*/
export default class AddClientSecretToParams {
enter({ clientSecret, params, ...ctx }) {
return { ...ctx, clientSecret, params: { ...params, client_secret: clientSecret } };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If client secret is not set, this could throw an error saying that client secret is missing. I hit this couple of times in my tests yesterday and was wondering why things don't work. The downside then is that client secret is made mandatory, which it today is yes, but maybe not for all token exchanges in the future?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the check.

If in the future we add token exchanges that don't require a client secret, I think we can make the check based on the params given to this interceptor.

Copy link
Member

@rap1ds rap1ds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but test carefully! It's quite easy to get these things wrong Imo. Retries and all are quite hard and complex to understand.

One comment/change request: I'd love to see some tests for this. Have a look at https://github.com/sharetribe/flex-sdk-js/blob/master/src/fake/auth.js . Testing against fake implementation of the server is a bit meh but it's still better than no tests imo.

src/sdk.js Show resolved Hide resolved
@kpuputti
Copy link
Contributor Author

kpuputti commented May 8, 2020

I have tested locally against the production API that an expired access token will fetch a new access token with the refresh token, and retry the token exchange.

I added a separate card for proper tests for this, so those will come later.

@kpuputti kpuputti merged commit 956790c into master May 8, 2020
@kpuputti kpuputti deleted the token-exchange branch May 8, 2020 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants