Skip to content
This repository has been archived by the owner on Nov 5, 2019. It is now read-only.

Adds support for RFC7636 PKCE #588

Merged
merged 1 commit into from
Aug 11, 2016
Merged

Conversation

bjmc
Copy link
Contributor

@bjmc bjmc commented Aug 4, 2016

This adds support for Proof Key for Code Exchange (PKCE) as specified by RFC7636. This is particularly useful for installable applications (either desktop or mobile) that cannot protect a client secret.

@theacodes
Copy link
Contributor

Thank you for this contribution!

Lint seems to be failing in travis, see here. Please fix lint errors.

@@ -37,6 +37,7 @@
from oauth2client import clientsecrets
from oauth2client import transport
from oauth2client import util
from oauth2client.pkce import code_verifier, code_challenge

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@theacodes theacodes self-assigned this Aug 4, 2016

from base64 import urlsafe_b64encode
from hashlib import sha256
from os import urandom

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@bjmc bjmc force-pushed the PKCE_support branch 2 times, most recently from b6a38dc to d485246 Compare August 4, 2016 19:26
@bjmc
Copy link
Contributor Author

bjmc commented Aug 4, 2016

I think I've finally mollified Travis-CI. How are people feeling?

@nathanielmanistaatgoogle
Copy link
Contributor

I developed an upset stomach and went home for the afternoon. Thanks for asking! Too often these code reviews are coldly technical and lacking the human element...

@@ -1872,6 +1878,7 @@ def __init__(self, client_id,
self.device_uri = device_uri
self.token_info_uri = token_info_uri
self.authorization_header = authorization_header
self.pkce = pkce

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@bjmc
Copy link
Contributor Author

bjmc commented Aug 4, 2016

Feel better! 🏥 💉

number of bytes of entropy to include in verifier.

Returns:
Bytestring

This comment was marked as spam.

@@ -0,0 +1,49 @@
# Copyright 2016 Google Inc. All rights reserved.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@theacodes
Copy link
Contributor

@bjmc gentle nudge here. I think @nathanielmanistaatgoogle still has some outstanding comments.

@bjmc
Copy link
Contributor Author

bjmc commented Aug 9, 2016

I thought I'd addressed them all? I've added the documentation requested, and I've underscore-prefixed everything in sight. 😉

@nathanielmanistaatgoogle Did I miss something?


@mock.patch('oauth2client._pkce.os.urandom')
def test_verifier(self, fake_urandom):
rand = (b'\x98\x10D7\xf3\xb7\xaa\xfc\xdd\xd3M\xe2'

This comment was marked as spam.

b'\x8dv\\\xa7/\x81\xf3J\x98\xc3\x90\xee'
b'\xb0\x8c\xb7Zc#\x05M0O\x08\xda\t\x1f\x07')
fake_urandom.return_value = rand
expected = (b'mBBEN_O3qvzd003ioywGoLCptI_L0PWGTjJwjF0hV5rt'

This comment was marked as spam.

@nathanielmanistaatgoogle
Copy link
Contributor

Three very-small action items.

Please squash commits and ensure that your commit message conforms to the guidelines.

... and thank you very much for the contribution and for enduring our onerous code review!

@bjmc
Copy link
Contributor Author

bjmc commented Aug 9, 2016

Okay, made those changes. One thing I'm actually wondering though: Should we have a way to pass in the code_verifier? Either as an argument to step2_exchange() or to the constructor? I know users could pickle the entire flow object in order to hold onto the generated code_verifier, but some people might rather not have to store the entire object, and just pass in the code_verifier before performing the exchange step.

Also, we probably can't change this any time soon, but OAuth2WebServerFlow should probably be renamed something more like OAuth2AuthorizationCodeFlow since it would be used for installed applications in this case.

@nathanielmanistaatgoogle
Copy link
Contributor

I'm not actually enough of a subject matter expert to judge. @jonparrott?

@theacodes
Copy link
Contributor

Should we have a way to pass in the code_verifier?

Yes. Put it in the place that makes the most sense, probably the constructor.

Also, we probably can't change this any time soon, but OAuth2WebServerFlow should probably be renamed something more like OAuth2AuthorizationCodeFlow

Agreed, we will probably address this during the great refactor (#597)

@theacodes
Copy link
Contributor

To qualify - I would do the following:

  1. Make _code_verifier a public attribute (rename to code_verifier.
  2. Add an optional parameter code_verifier to the constructor.
  3. Generate a new code_verifier if None is specified to the constructor.

@bjmc
Copy link
Contributor Author

bjmc commented Aug 10, 2016

@jonparrott What do you think of that?

Also, there's some weird build failure related to django that I don't think has anything to do with this changeset.

@bjmc
Copy link
Contributor Author

bjmc commented Aug 10, 2016

Also: Do I need to add the same arguments to these two helper functions? Or is it fine that they don't accept all the same arguments as the OAuth2WebServerFlow() constructor?

@theacodes
Copy link
Contributor

@bjmc I want to say yes.

@bjmc
Copy link
Contributor Author

bjmc commented Aug 10, 2016

Do you want me to change those to pass though all the constructor arguments, or just the two I'm adding right here?

@theacodes
Copy link
Contributor

Let's keep it minimal and just the two you're adding.

RFC7636 extends OAuth2 to include a challenge-response protocol
called "Proof Key for Code Exchange" (PKCE) in order to mitigate
attacks in situations where clients that cannot protect a client
secret (e.g.installed desktop applications).
@bjmc
Copy link
Contributor Author

bjmc commented Aug 11, 2016

Are people happy with this? I rebased to drop Python 3.3 tests.

@theacodes theacodes merged commit 3614fd1 into googleapis:master Aug 11, 2016
@theacodes
Copy link
Contributor

@bjmc thanks for your contribution!

@pferate
Copy link
Contributor

pferate commented Aug 11, 2016

@jonparrott, just rebased onto this commit and found some problems. unittest2 was recently removed so these tests are failing now. I'm about to submit another PR concerning imports, should I update it there, or should it be handled a different way.

@theacodes
Copy link
Contributor

@pferate separate commits/PRs are always better

@pferate
Copy link
Contributor

pferate commented Aug 11, 2016

OK. 2 PRs are coming down the pipes.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants