Validating Google ID tokens in C#

后端 未结 3 1839
猫巷女王i
猫巷女王i 2021-02-13 22:38

I need to validate a Google ID token passed from a mobile device at my ASP.NET web api.

Google have some sample code here but it relies on a JWT NuGet package which is .

3条回答
  •  自闭症患者
    2021-02-13 23:24

    According to this github issue, you can now use GoogleJsonWebSignature.ValidateAsync method to validate a Google-signed JWT. Simply pass the idToken string to the method.

    var validPayload = await GoogleJsonWebSignature.ValidateAsync(idToken);
    Assert.NotNull(validPayload);
    

    If it is not a valid one, it will return null.

    Note that to use this method, you need to install Google.Apis.Auth nuget firsthand.

提交回复
热议问题