google / GoogleSignIn-iOS

Enables iOS and macOS apps to sign in with Google.
https://developers.google.com/identity/sign-in/ios
Apache License 2.0
447 stars 179 forks source link

How to pass in nonce? #135

Open DanMossa opened 2 years ago

DanMossa commented 2 years ago

Context: You can not pass a rawNonce to signInWithGoogle.

When using signInWithGoogle on Android, the returned idToken does not return a nonce. This makes sense because a rawNonce is not passed in.

The same exact code when run on iOS, returns a hashed nonce in the idToken. This does not make sense since we can not pass in a nonce. Where is the nonce coming from?

petea commented 2 years ago

In the case of Google Sign-In for iOS and macOS, nonce values are being generated by AppAuth and included with the auth request. During ID token validation, the nonce value of the ID token is then verified using the originally generated value.

DanMossa commented 2 years ago

@petea Oh interesting. Now if I want to send this JWT with the hashed nonce, how can I get the original nonce used so that i can verify this myself on the backend?

How can I get the originally generated value?

I also see that the comment says

@discussion If this value is not explicitly set, this library will automatically add nonce and perform appropriate validation of the nonce in the ID Token.

Is there no way to explicitly set this value?

petea commented 2 years ago

How can I get the originally generated value?

The nonce generated by AppAuth isn't available via the Google Sign-In API surface. Currently, the recommended approach to server-side validation of the ID token doesn't include validation of the nonce.

Is there no way to explicitly set this value?

AppAuth allows you to provide a specific nonce, if desired. However, Google Sign-In does not expose this capability in its API surface.

DanMossa commented 2 years ago

@petea Oh I see, thanks for the clarification!

The lack of getting the raw nonce or specifying the raw nonce is blocking a few different users.

Would a PR to fix this be welcome in the future?

toshi0383 commented 1 year ago

We need nonce support, too. Apple and LINE supports this, so please consider. We want to prevent Replay Attack.

petea commented 1 year ago

@DanMossa, PRs are always welcome. Can you provide more detail on the specific use cases that are blocked here? Are they all related to server-side verification of the nonce?

@toshi0383 is the existing automatic client-side nonce generation / validation not adequate for your needs?

toshi0383 commented 1 year ago

automatic client-side nonce generation

@petea We generate nonce in our server-side, so we need manual way to do this. I have a brand new branch for this, so will tackle in a PR in a few minutes!

toshi0383 commented 1 year ago

Done! https://github.com/google/GoogleSignIn-iOS/pull/244

mdmathias commented 1 year ago

Hi all! Many apologies for the delay. Thanks for your patience.

Would you be able to share more information about your use-case? It seems to deviate from the typical use case where the nonce is generated by the client.

In general, it seems fine for GSI to provide an API to ingest a nonce to pass along to OIDAuthorizationRequest in AppAuth.

hf commented 11 months ago

The nonce generated by AppAuth isn't available via the Google Sign-In API surface. Currently, the recommended approach to server-side validation of the ID token doesn't include validation of the nonce.

This is not true. The OIDC spec which Google follows explicitly states:

nonce String value used to associate a Client session with an ID Token, and to mitigate replay attacks. The value is passed through unmodified from the Authentication Request to the ID Token. If present in the ID Token, Clients MUST verify that the nonce Claim Value is equal to the value of the nonce parameter sent in the Authentication Request. If present in the Authentication Request, Authorization Servers MUST include a nonce Claim in the ID Token with the Claim Value being the nonce value sent in the Authentication Request. Authorization Servers SHOULD perform no other processing on nonce values used. The nonce value is a case sensitive string.

Please allow for people to be able to extract the nonce you send to Google.

SunilKividor commented 2 months ago

@petea @toshi0383 can u help me setting up nonce in the google sign in package? Its an urgent usecase

toshi0383 commented 2 months ago

@SunilKividor Hire someone and leave. I have nothing to do with ur use case. Stop mentioning us for nothing.

SunilKividor commented 2 months ago

@toshi0383 Thankyou for the response. We have moved to google credential management for setting up authentication with nonce. I appreciate your time.

Massimiliano-solutiontech commented 2 months ago

Any news on that? The only way to set the nonce is to use AppAuth?

toshi0383 commented 2 months ago

FYI my fork is an option too. https://github.com/google/GoogleSignIn-iOS/pull/244 We're using this in production without any issues.

vonovak commented 2 months ago

I have opened a PR to support this: https://github.com/google/GoogleSignIn-iOS/pull/402