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

Restore session from chosen adapter? #268

Closed
balinterdi opened this issue Jan 20, 2016 · 7 comments

Comments

Projects
None yet
3 participants
@balinterdi
Copy link
Contributor

commented Jan 20, 2016

  1. Users could authenticate themselves against multiple providers in the same app and I think it's a good idea to have the open and close methods of the adapters for these providers stored in a file that is named according to the provider (for example under torii-adapters/google-oauth2-bearer.js).
  2. When it comes to the automatic restoring (fetching) of the session, you need to choose one adapter whose fetch method will be called, you cannot restore a session from multiple providers. My issue is that this is automatically assumed to be the application which forces me to always create an application adapter to be able to define its fetch method.

If I want to have both 1. and 2. implemented then I need two adapters, one application.

This is not really a biggie but I wonder if we might have a configuration option to designate which adapter should restore the session, something like the following:

// config/environment.js
torii: {
  sessionServiceName: 'session',
  restoreFrom: 'google-oauth2-bearer',
  (...)
}
@mixonic

This comment has been minimized.

Copy link
Contributor

commented Jan 20, 2016

@balinterdi you can just have google-oauth2-bearer inherit from application, or re-export. This is pretty standard through the Ember ecosystem and I'd like to keep it.

@balinterdi

This comment has been minimized.

Copy link
Contributor Author

commented Jan 21, 2016

I tried the following:

// app/torii-adapters/google-oauth2-bearer.js
import ApplicationAdapter from 'torii/adapters/application';

export default ApplicationAdapter.extend({
  open(authorization){
    (...)
  },

  fetch() {
    (...)
  },

  close() {
    (...)
  }
});

But when Torii fetches the session, it still finds the default, empty implementation of ApplicationAdapter which just throws an error. Maybe I have to inherit and re-export? If so, do I have to do the re-exporting in an initializer? Thank you.

@kategengler

This comment has been minimized.

Copy link

commented Jan 21, 2016

I was attempting to have an adapter named 'api' recently, matching my provider. It worked with 'open' and 'close' but not with 'fetch'. Once I moved the adapter to be named 'application', it worked; I think this may be a bug.

@balinterdi

This comment has been minimized.

Copy link
Contributor Author

commented Jan 22, 2016

@kategengler I think it's simply because Torii uses the application adapter to fetch (restore) the session, see here.

That's also what my point is with this ticket, I'd like to have all methods in place, preferably named "semantically" (in your case: api).

If you don't need a configuration option for that, all the better, I just don't know how to make what Matt said above work :)

@kategengler

This comment has been minimized.

Copy link

commented Jan 22, 2016

@balinterdi Thanks, I didn't think about it enough before to realize that its only the auto-restoring of the session provided by the Router DSL that has this problem. Previously I had done: this.get('service').fetch('api'); but of course the built in method can't know what provider I mean to open, hence your suggestion of a configuration option.

Re, part 1 of your issue, I think you may have meant "methods of the adapters for these providers stored in a file that is named according to the provider (for example under torii-adapters/google-oauth2-bearer.js)."

@balinterdi

This comment has been minimized.

Copy link
Contributor Author

commented Jan 22, 2016

Yes, that's what I meant, thank you, I've now fixed it.

@balinterdi

This comment has been minimized.

Copy link
Contributor Author

commented Feb 4, 2016

I think I understood (and made to work) what Matt had in mind:

// app/torii-adapters/google-oauth2-bearer.js
export default Ember.Object.extend({
  fetch() {
    (...)
  },

  open(authorization){
    (...)
  },

  close() {
    (...)
  },
});
// app/torii-adapters/application.js
import GoogleOAuth2BearerAdapter from './google-oauth2-bearer';

export default GoogleOAuth2BearerAdapter;

@mixonic Is this what you meant?

I find this a convenient way as a solution to my problem and is a better than adding a configuration variable, so I'm going to close this issue.

@balinterdi balinterdi closed this Feb 4, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.