在服务器调用中使用Google API GoogleJsonWebSignature.ValidateAsync(...) [英] Using Google API GoogleJsonWebSignature.ValidateAsync(...) in server call

查看:162
本文介绍了在服务器调用中使用Google API GoogleJsonWebSignature.ValidateAsync(...)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在C#Web应用程序中实现Google SSO.它看起来很简单. 基于本教程,Google在网络上发挥了魔力浏览器以获取Id_Token JWT.我将令牌传递给令牌,并将其传递给我的Web服务以进行验证,并使用令牌将其与应用程序中的用户进行匹配.

I am trying to implement Google SSO in my C# web application. It seemed to be pretty straightforward. Based on this tutorial, Google does its magic in the web browser to get an Id_Token JWT. I pass the token is passed it to my web service for validation and use it to match it to a user in the application.

尽管我不确定我使用服务器端Google API的方法是否正确,但我遇到的麻烦是试图弄清楚如何使用Google API中的异步调用来查看返回的内容.

Although I am not sure if my approach with the server-side Google API is correct yet, my big hangup is trying to figure out how to work with the async call in the Google API to see what I get back.

使用Google.Apis.Auth命名空间,我的代码非常简单:

My code is pretty simple using the Google.Apis.Auth namespace:

public async Task<GoogleJsonWebSignature.Payload> wfValidateAsync(string pId_Token)
{
    GoogleJsonWebSignature.Payload Sig = await GoogleJsonWebSignature.ValidateAsync(pId_Token, null, false);

    return Sig;
}

尽管这种异步/等待模式是全新的,但我确实对AngularJS/NodeJS Promise/回调有一定的经验.我的挑战是,似乎异步方法只能一直被其他异步方法一直备份到调用堆栈中.我认为这意味着在异步响应完成之前结束服务调用,并且服务可以对结果采取行动.

Although brand new to this async/await paradigm, I do have some experience in AngularJS / NodeJS promises / callbacks. My challenge is that it seems async methods can only be called by other async methods all the way back up the call-stack. I think it means ending the service call before the async response finishes and the service can act on the result.

另外,对于创建单元测试,将异步放入[TestMethod]方法会使它从测试资源管理器中完全消失.我不确定如何测试/调试这个难题.

Also, for creating unit tests, putting async into the [TestMethod] method makes it completely disappear from the test explorer. I'm not sure how to test/debug this conundrum.

在此先感谢任何可以帮助我将头重新拧紧的人.

Thanks in advance to anyone who can help me screw my head back on straight with this.

推荐答案

尽管这种异步/等待模式是全新的,但我确实对AngularJS/NodeJS Promise/回调有一定的经验.

Although brand new to this async/await paradigm, I do have some experience in AngularJS / NodeJS promises / callbacks.

但不要使用 Typescript ,对吧?

我的挑战是,似乎异步方法只能一直由其他异步方法一直备份到调用堆栈中.

My challenge is that it seems async methods can only be called by other async methods all the way back up the call-stack.

他们应该.否则,可能会发生坏事.

They should. Bad things can happen if you don't.

我认为这意味着在异步响应完成之前结束服务调用,并且服务可以对结果采取行动.

I think it means ending the service call before the async response finishes and the service can act on the result.

不!编译器使用async修饰符为方法生成状态机,并且await关键字表示做其他事情,完成后我会回到这里".

No! The compiler generates a state machine for methods with the async modifier and the await keyword means "go do something else and I'll come back here when I'm done".

另外,对于创建单元测试,将异步放入[TestMethod]方法会使它从测试资源管理器中完全消失.我不确定如何测试/调试这个难题.

Also, for creating unit tests, putting async into the [TestMethod] method makes it completely disappear from the test explorer. I'm not sure how to test/debug this conundrum.

您可能正在使测试方法成为async void.它们应该为async Task,以便测试引擎知道何时完成测试.

You're probably making your test methods async void. They should be async Task in order for the test engine to know when the test is done.

看看 Stephen Cleary

Have a look at Stephen Cleary's blog. He has lots of content on async-await.

这篇关于在服务器调用中使用Google API GoogleJsonWebSignature.ValidateAsync(...)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆