最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

如何使用Hapibell使用Twitter登录用户?

运维笔记admin14浏览0评论

如何使用Hapi / bell使用Twitter登录用户?

如何使用Hapi / bell使用Twitter登录用户?

我正在尝试使用hapi/bell设置Twitter身份验证流,但是仅遵循简单的示例,它似乎不起作用。这是我的基本代码:

'use strict';

const Hapi = require('@hapi/hapi');
const Bell = require('@hapi/bell');

const init = async () => {
  const server = Hapi.server({port: 3333, host: 'localhost'});

  // Register bell with the server
  await server.register(Bell);

  server.auth.strategy('twitter', 'bell', {
    provider: 'twitter',
    password: 'test_test',
    clientId: 'my_consumer_api_key',
    clientSecret: 'my_consumer_api_key_secret',
    isSecure: false 
  });


  server.route({
    method: 'GET', // Must handle both GET and POST
    path: '/bell/door', // The callback endpoint registered with the provider
    options: {
      auth: 'twitter',
      handler: function(request, h) {

        if (!request.auth.isAuthenticated) {
          return `Authentication failed due to: ${request.auth.error.message}`;
        }

        return h.redirect('/home');
      }
    }
  });

  server.events.on('request', (request, event, tags) => {
    if (event.channel === 'error') {
      console.dir(event.error.data, 4);
    }
  });

  await server.start();
  console.log('Server running on %s', server.info.uri);
};

// process.on('unhandledRejection', err => {
//   console.log(err);
//   process.exit(1);
// });

init();

这是我的应用程序的配置:

但是当我使用浏览器转到http://localhost:3333/bell/door时,出现此错误:

{ Error: Failed obtaining twitter temporary credentials at exports.Client.internals.Client.internals.Client._request (/Users/ben/pro/tmp/authy/node_modules/@hapi/bell/lib/oauth.js:453:20) at process._tickCallback (internal/process/next_tick.js:68:7) data: { Error: Response Error: 403 Forbidden at internals.Client._shortcut (/Users/ben/pro/tmp/authy/node_modules/@hapi/wreck/lib/index.js:635:11) at process._tickCallback (internal/process/next_tick.js:68:7) data: { isResponseError: true, headers: [Object], res: [IncomingMessage], payload: <Buffer 3c 3f 78 6d 6c 20 76 65 72 73 69 6f 6e 3d 22 31 2e 30 22 20 65 6e 63 6f 64 69 6e 67 3d 22 55 54 46 2d 38 22 3f 3e 3c 65 72 72 6f 72 73 3e 3c 65 72 72 ... > }, isBoom: true, isServer: false, output: { statusCode: 403, payload: [Object], headers: {} }, reformat: [Function], typeof: [Function: Error] }, isBoom: true, isServer: true, output: { statusCode: 500, payload: { statusCode: 500, error: 'Internal Server Error', message: 'An internal server error occurred' }, headers: {} }, reformat: [Function], typeof: [Function: internal] }

我在做什么错?

我正在尝试使用hapi / bell来建立一个Twitter身份验证流,但是仅遵循简单的示例,它似乎不起作用。这是我的基本代码:“使用严格”; const Hapi = require('@ hapi / hapi'); ...

回答如下:
发布评论

评论列表(0)

  1. 暂无评论