loopbackio / loopbackio/loopback-next
How to integrate passport authentication without express web app?
まだ誰も着手していません。
- 主要言語
- TypeScript
- スター
- 5.1k
- フォーク
- 1.1k
- 平均マージ
- 2日 21時間
- マージ済み PR(30日)
- 27
説明
Describe the bug
I have my front-end separated from my loopback application and I am trying to implement authentication through passport.
However I receive the following error (after it is making a GET request to https://myapi.com/auth/thirdparty/twitter):
Request GET /auth/thirdparty/twitter failed with status code 500. InternalServerError: Error: OAuth authentication requires session support. Did you forget to use express-session middleware?
The only adjustment I have made is to remove the web-application folder from the loopback-passport example repository.
I then tried to integrate it with my React JS application.I made slight modifications to the src/controllers/oauth2.controller.ts:
@authenticate('oauth2')
@get('/auth/thirdparty/{provider}')
/**
* This method uses the @authenticate decorator to plugin passport strategies independently
*
* Endpoint: '/auth/thirdparty/{provider}'
* an endpoint for api clients to login via a third party app, redirects to third party app
*/
loginToThirdParty(
@param.path.string('provider') provider: string,
@inject(AuthenticationBindings.AUTHENTICATION_REDIRECT_URL)
redirectUrl: string,
@inject(AuthenticationBindings.AUTHENTICATION_REDIRECT_STATUS)
status: number,
@inject(RestBindings.Http.RESPONSE)
response: Response,
) {
return {redirectUrl: redirectUrl};
}
@oAuth2InterceptExpressMiddleware()
@get('/auth/thirdparty/{provider}/callback')
/**
* This method uses the passport strategies as express middleware
*
* Endpoint: '/auth/thirdparty/{provider}/callback'
* an endpoint which serves as a oauth2 callback for the thirdparty app
* this endpoint sets the user profile in the session
*/
async thirdPartyCallBack(
@param.path.string('provider') provider: string,
@inject(SecurityBindings.USER) user: UserProfile,
@inject(RestBindings.Http.REQUEST) request: Request,
@inject(RestBindings.Http.RESPONSE) response: Response,
) {
// const profile = {
// ...user.profile,
// };
// request.session.user = profile;
// response.redirect('/auth/account');
return response;
}
In src/authentication-strategy-providers/twitter.express-mv.ts I also tried to set session to false:
@injectable.provider({scope: BindingScope.SINGLETON})
export class TwitterOauthExpressMiddleware implements Provider<ExpressRequestHandler> {
constructor(
@inject('twitterStrategy')
public twitterStrategy: TwitterStrategy,
) {
passport.use(this.twitterStrategy);
}
value() {
return passport.authenticate('twitter',{session: false});
}
}
but unfortunately no luck.
Any support is welcome!
Logs
No response
Additional information
No response
Reproduction
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず passport-login の例と、参照されている src/controllers/oauth2.controller.ts および src/authentication-strategy-providers/twitter.express-mv.ts ファイルを読み、OAuth コールバックとセッションオプションがどのように接続されているかを追跡します。完了とみなすには、報告されているセッションエラーなしで分離された React クライアントに対応できる認証アプローチが確認され、再現可能なテストまたは文書化された統合手順が用意されている必要があります。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- node.js, react, typescript
- 領域
- api, authentication, backend
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- 説明が足りない
- 初心者へのやさしさ
- 25/100