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

[discuss] accounts-server token creator #774

Merged

Conversation

ozsay
Copy link
Contributor

@ozsay ozsay commented Aug 20, 2019

Hi,

In our project, we use a 3rd party authenticator service. This service manages access tokens itself. We wrote an AuthenticationService to support it, but it has duplicate code with accounts-server (and specific graphql endpoints) since we can't use its loginWithService and refreshTokens functionality.

The reason why we can't use loginWithService is the way we deliver our 3rd party token to the client. The only way for us to do that with accountsjs is to use it as a session token. then we create access token and refresh token using accounts and deliver them. since accounts-server generates the session token itself, loginWithService is not capable of supporting this scenario.

The way we thought of solving it, is to provide accounts-server with a custom token creator which will request the access token from the authenticator service and return it to be used as a session token.

The other problem is with refreshTokens. When the authenticator service tells us to refresh its tokens, we currently invalidate the current session and create a new one with the new access token. we want to be able to use accountsServer functionality to do that. that's why we want to add createSessionTokenOnRefresh option to create a new session token when refreshing tokens.

These two changes allow us to use more of accounts-server and client functionality without implementing it ourselves.

@davidyaha @elie222 FYI

@codecov
Copy link

codecov bot commented Aug 21, 2019

Codecov Report

Merging #774 into master will increase coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #774      +/-   ##
==========================================
+ Coverage   95.15%   95.17%   +0.02%     
==========================================
  Files          80       80              
  Lines        1774     1783       +9     
  Branches      348      352       +4     
==========================================
+ Hits         1688     1697       +9     
  Misses         78       78              
  Partials        8        8
Impacted Files Coverage Δ
packages/server/src/accounts-server.ts 90.81% <100%> (+0.3%) ⬆️
packages/database-mongo/src/mongo.ts 99.31% <100%> (+0.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dca8132...31f6a21. Read the comment docs.

@codecov
Copy link

codecov bot commented Aug 21, 2019

Codecov Report

Merging #774 into master will increase coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #774      +/-   ##
==========================================
+ Coverage   95.15%   95.17%   +0.02%     
==========================================
  Files          80       80              
  Lines        1774     1783       +9     
  Branches      348      352       +4     
==========================================
+ Hits         1688     1697       +9     
  Misses         78       78              
  Partials        8        8
Impacted Files Coverage Δ
packages/server/src/accounts-server.ts 90.81% <100%> (+0.3%) ⬆️
packages/database-mongo/src/mongo.ts 99.31% <100%> (+0.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dca8132...cf4554f. Read the comment docs.

@davidyaha davidyaha requested a review from pradel August 22, 2019 13:54
Copy link
Member

@pradel pradel left a comment

Choose a reason for hiding this comment

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

These options make sense, just left some minor comments but otherwise, the pr looks good!

@@ -24,4 +25,6 @@ export interface AccountsServerOptions {
siteUrl?: string;
prepareMail?: PrepareMailFunction;
sendMail?: SendMailType;
tokenCreator?: TokenCreator;
Copy link
Member

Choose a reason for hiding this comment

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

Does it needs to be a separate interface or can it be just a function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

as I think about our use-case, the creator should receive "static" options. so I think it will be better to implement it as an interface that you can instantiate ratter than passing the options in the function

packages/server/src/types/accounts-server-options.ts Outdated Show resolved Hide resolved
Copy link
Member

@TimMikeladze TimMikeladze left a comment

Choose a reason for hiding this comment

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

Looks good.

@davidyaha davidyaha merged commit 836739d into accounts-js:master Aug 29, 2019
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.

4 participants