Skip to content
This repository has been archived by the owner on Mar 21, 2021. It is now read-only.

Create VanillaConnect library #1

Merged
merged 32 commits into from
Oct 5, 2017
Merged

Create VanillaConnect library #1

merged 32 commits into from
Oct 5, 2017

Conversation

DaazKu
Copy link
Contributor

@DaazKu DaazKu commented Sep 11, 2017

Information

Original spec:

Read the README.md

Notable differences:

  • We use ?jwt instead of ?sso since the latter is reserved to jsConnect push sso/embed
  • Embed Flow === Push SSO
  • The push SSO JWT' claim contains the 'aud' (audience) field which must be set to 'pushsso'

TODO

  • Create the main class
    • Handle request JWT
    • Handle response JWT
  • Create a provider class for clients to use.
    • URL whitelist for redirect
    • Generate response URL containing either the provider's claim or the errors if something went wrong. (If the redirect url is not whitelisted we will still redirect to it but the response JWT will contain an error)
    • Push SSO (allow to create a JWT that can be passed in the querystring to authenticate a user)
  • Unit tests
    • Travis
  • README documentation
    • Briefly explain the purpose of this library and how it works.
    • Explain the whitelist
    • Provide an example
  • Composer

How to test

You can see the library used here and here as a pushsso.

@DaazKu DaazKu added the WIP This pull request is currently in progress. Do NOT merge it. label Sep 11, 2017
@DaazKu DaazKu added this to the 2017-Q3-6 milestone Sep 11, 2017
@DaazKu DaazKu closed this Sep 22, 2017
@DaazKu DaazKu reopened this Sep 22, 2017
@DaazKu DaazKu mentioned this pull request Sep 28, 2017
@DaazKu DaazKu requested a review from initvector October 4, 2017 16:32
@DaazKu DaazKu removed the WIP This pull request is currently in progress. Do NOT merge it. label Oct 4, 2017
@DaazKu DaazKu removed the request for review from initvector October 4, 2017 16:33
@DaazKu DaazKu added WIP This pull request is currently in progress. Do NOT merge it. and removed WIP This pull request is currently in progress. Do NOT merge it. labels Oct 4, 2017
@DaazKu DaazKu modified the milestones: 2017-Q3-6, 2017-Q4-1 Oct 4, 2017
/**
* List of errors that were encountered during the validation process.
*
* @var array
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're switching up the doc style here. This should probably look like:

/**
 * @var array List of errors that were encountered during the validation process.
 */

public static function extractClientID($jwt) {
$parts = explode('.', $jwt);
if (count($parts) !== 3) {
throw new Exception('Wrong number of segments.');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an Exception class available while you're in the Vanilla\VanillaConnect namespace? I think you might be missing use Exception in this class file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed

}

/**
* @return string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need a description for this method. There are several more instances, below, that also need descriptions.

public function createRequestAuthJWT($nonce, array $extraClaimItems = []) {
$authHeader = array_merge(
self::JWT_REQUEST_HEADER_TEMPLATE,
['azp' => $this->clientID]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this fail if $clientID hasn't been set? This same question applies to the createResponseAuthJWT method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not possible to not set the clientID since it is required by the constructor.
I'll add exception to the constructor to make sure that no one does:

new VanillaConnect(null, '');

* @param array $jwtHeader Array that will receive the JWT header's content on success.
* @return array|bool The decoded payload or false otherwise.
*/
public function validateRequest($jwt, &$jwtClaim=[], &$jwtHeader=[]) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should give the equal signs a little space

* It is a pretty loose regex that should enforce what is needed without blocked weird cases.
*
* One line regex:
* /^(?<scheme>(?:https?:)?\/\/)(?:[^\s]+?@)?(?<host>[^\/\s]+)(?<path>\/[^?#\s]*)$/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I appreciate the one-liner, but it looks to be missing the userpwd portion.

/**
* VanillaConnectProvider constructor.
*
* @param string S$clientID
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think an S got away from you.


if ($urlEncodingError) {
$errors['request_invalid_redirect_tip'] =
"Seems like the redirect URL was not properly encoded. Invalid character detected.";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why'd you go with the "double quote" string syntax here?

if ($this->vanillaConnect->validateRequest($requestJWT, $authClaim)) {
$nonce = $authClaim['nonce'];
} else {
$errors = $this->vanillaConnect->getErrors();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're recording specific errors in this function and then potentially overwriting all of them with whatever comes back from VanillaConnect.

$claim = ['errors' => $errors];
}

$responseJWT = $this->vanillaConnect->createResponseAuthJWT($nonce, $claim);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the sake of my IDE, can we set $nonce to null by default, so there's no perceived chanced it might not be set?

Copy link
Contributor Author

@DaazKu DaazKu Oct 5, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your IDE is stupid :P. There is no codepath where $nonce is not set.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

She's just sensitive, because the only times she sees it getting set are inside an if conditional block

@initvector initvector added the Revisit This pull request requires changes before it can be merged. label Oct 5, 2017
@DaazKu DaazKu removed the Revisit This pull request requires changes before it can be merged. label Oct 5, 2017
@initvector initvector merged commit 838657b into master Oct 5, 2017
@initvector initvector deleted the feature/initial branch October 5, 2017 21:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants