0

我想在everyauth openid 模块中定义的 OpenId 身份验证序列中再添加一个步骤。

我不确定everyauth 是否是为此而设计的。作者提到它是可定制的,但没有示例,我仍然是一个 javascript 新手。

例如,everyauth 中的 OAuth 模块定义了它的认证回调步骤,如下所示:

.get('callbackPath',                                                                                                                                               
     'the callback path that the 3rd party OAuth provider redirects to after an OAuth authorization result - e.g., "/auth/facebook/callback"')                     
  .step('getCode')
    .description('retrieves a verifier code from the url query')                                                                                                   
    .accepts('req res')  
    .promises('code')                                                       
    .canBreakTo('authCallbackErrorSteps')
  .step('getAccessToken')
    .accepts('code')
    .promises('accessToken extra')                                                                                                                                 
  .step('fetchOAuthUser')
    .accepts('accessToken')                                                                                                                                        
    .promises('oauthUser')
  .step('getSession')
    .accepts('req')
    .promises('session')
  .step('findOrCreateUser')                                                                                                                                        
    .accepts('session accessToken extra oauthUser')                                                                                                                
    .promises('user')
  .step('compile')
    .accepts('accessToken extra oauthUser user')
    .promises('auth')
  .step('addToSession')
    .accepts('session auth')                                                                                                                                       
    .promises(null)
  .step('sendResponse')
    .accepts('res')
    .promises(null)

如果我需要额外的自定义步骤,我应该怎么做?我宁愿不更改everyauth 模块源代码。

4

2 回答 2

4

It's quite some time this question was raised but no answer. I faced the same challenge just now and documenting my answer for benefit of other node noobs like me :)

I'm using Facebook authentication, and wanted to carry out some custom processing before response is sent to client after successful authentication. Instead of adding another step, I overrode the step 'sendResponse', added my custom logic, and then just delegated to the super 'sendResponse' implementation. Here is now my code looks like -

everyauth
    .facebook
    .sendResponse(function(res) {
        console.log('##### sendResponse custom step called #####');
        // --> Your custom logic here
        this._super();
    });

You can override it for a specific module such as facebook as shown above, or it can be done at 'everymodule' level.

Hope this helps.

于 2012-03-28T03:51:12.253 回答
0

另一个选项是addToSession步骤。它在 facebook、linkedin 和密码模块中可用。我发现sendResponse密码模块不起作用。如果您的自定义逻辑依赖于会话变量,这会简化事情。

于 2012-12-08T02:43:59.137 回答