Validating Google ID tokens in C#

后端 未结 3 1824
猫巷女王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:05

    ClientId also needs to be passed, which should be set from Google API Console. If only pass TokenId, GoogleJsonWebSignature throws error. This answer is in addition to @edmundpie answer

    var settings = new GoogleJsonWebSignature.ValidationSettings()
    {
     Audience = new List() { "[Placeholder for Client Id].apps.googleusercontent.com" }
    };
    
    var validPayload = await GoogleJsonWebSignature.ValidateAsync(model.ExternalTokenId, settings);
    

提交回复
热议问题