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

[SPIKE] DO NOT MERGE feat: try mw with passport login example #5302

Closed
wants to merge 10 commits into from

Conversation

deepakrkris
Copy link
Contributor

example for #5118

Checklist

👉 Read and sign the CLA (Contributor License Agreement) 👈

  • npm test passes on your machine
  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style guide
  • API Documentation in code was updated
  • Documentation in /docs/site was updated
  • Affected artifact templates in packages/cli were updated
  • Affected example projects in examples/* were updated

👉 Check out how to submit a PR 👈


@intercept('PassportInitMW')
@intercept('PassportSessionMW')
@intercept('FacebookOauth2MW')
Copy link
Contributor

Choose a reason for hiding this comment

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

It can be simplified as @intercept('PassportInitMW', 'PassportSessionMW', 'FacebookOauth2MW').

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agreed

@@ -91,3 +97,34 @@ export const mapProfile = function (user: User): UserProfile {
};
return userProfile;
};

export class PassportInitMW implements Provider<Interceptor> {
Copy link
Contributor

Choose a reason for hiding this comment

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

There is no need to wrap a simple Express middleware as provider class for local interceptors. You simply bind it to the context, or create a binding for it:

app.bind('PassportInitMW').to(toInterceptor(passport.initialize());
// or
const binding = new Binding('PassportInitMW').to(toInterceptor(passport.initialize());

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agreed

…ware

- add `Middleware` as interceptors that use request context
- add `InvokeMiddleware` to invoke middleware in a chain
- add extension points for Middleware extensions
- add helper methods to adapt express middleware as interceptors
- add helper methods to adapt LoopBack middleware chain as Express middleware
- add ExpressServer and ExpressApplication to extend Express with LoopBack core
- add `InvokeMiddleware` action to the default sequence
- add `middleware/expressMiddleware` APIs to RestServer/RestApplication
- use middleware APIs to register CORS and OpenAPI spec endpoints

BREAKING CHANGE: `basePath` now also applies to endpoints that serve OpenAPI
specs. For example, the OpenAPI specs are available at `/api/openapi.json`
or `/api/openapi.yaml` if the base path is set to `/api`.
@raymondfeng raymondfeng force-pushed the middleware-interceptor branch from c97955f to 2539258 Compare May 1, 2020 04:02
@deepakrkris deepakrkris force-pushed the express-passport-middleware branch from 59d2891 to 16bce44 Compare May 1, 2020 16:43
@deepakrkris deepakrkris requested a review from emonddr as a code owner May 1, 2020 16:43
constructor(
) {}

@intercept('passport-init-mw', 'passport-session-mw', 'passport-facebook')
Copy link
Contributor

@raymondfeng raymondfeng May 1, 2020

Choose a reason for hiding this comment

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

It is possible to define a custom decorator such as:

export function facebookLogin() {
  return intercept('passport-init-mw', 'passport-session-mw', 'passport-facebook');
}

Then we can use @facebookLogin().

@raymondfeng
Copy link
Contributor

Nice and clean. 👍

@raymondfeng raymondfeng force-pushed the middleware-interceptor branch 8 times, most recently from abc2ee8 to 7970266 Compare May 5, 2020 02:18
@deepakrkris deepakrkris force-pushed the express-passport-middleware branch from bda5b70 to 3931b3b Compare May 5, 2020 15:41
@deepakrkris
Copy link
Contributor Author

#5118 merged now, opening #5339 for master

@deepakrkris deepakrkris closed this May 5, 2020
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.

2 participants