[英]oAuth on the front end or server side?
我有一個 MERN 應用程序(在前端和節點上反應,快遞和后端在 Mongo 上反應)
我希望為用戶實現 oAuth 登錄。
到目前為止,我正在使用 Google api 在前端執行自動操作,然后將令牌發送到我獲取 Google 用戶的服務器並檢查數據庫是否存在用戶 ID 或創建一個新用戶並返回一個 jwt 以備將來使用驗證。
現在我正在考慮使用passportjs作為我的oauth中間件(主要是因為我需要有更多的Auth提供者,比如Facebook等)但是只在服務器上進行Auth是一個好主意嗎?
我也在考慮使用具有前端和服務器端選項的 auth0,但也不確定哪種策略更好。
任何幫助是極大的贊賞。
我最近花了幾個晚上。 這對我幫助很大。
一般來說:
const loginGoogle = async () => {
const loadGapi = () =>
new Promise((resolve, reject) => {
const script = document.createElement('script');
script.src = 'https://apis.google.com/js/api.js'; //loading gapi Script
console.log('SCRIPT: ', script);
script.onload = () => {
console.log('GAPIS SCRIPT LOADED');
gapi.load('auth2', () => {
const auth2 = gapi.auth2.init(options);
console.log('AUTH2: ', auth2);
resolve(auth2);
});
};
document.body.appendChild(script);
});
const ath2 = await loadGapi();
const code = await ath2.grantOfflineAccess();
return PostApi('auth/getgoogletoken', code); // sending to server for further processing
};
讓我知道,如果我可以為您提供更多信息,我已經使用 nginx/node/passport 實現了它並在前端做出反應。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.