Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

Commit

Permalink
extracted server config from verifier, unit tested all the things
Browse files Browse the repository at this point in the history
  • Loading branch information
ctrl-f5 committed Nov 17, 2020
1 parent 3768fa5 commit 6449d31
Show file tree
Hide file tree
Showing 30 changed files with 1,308 additions and 473 deletions.
1 change: 1 addition & 0 deletions .phpunit.result.cache
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
C:37:"PHPUnit\Runner\DefaultTestResultCache":5498:{a:2:{s:7:"defects";a:19:{s:56:"Test\Unit\Discovery\OauthTest::sets_well_known_correctly";i:4;s:75:"Test\Unit\JwtVerifierBuilderTest::discovery_defaults_to_oauth_when_building";i:4;s:88:"Test\Unit\JwtVerifierBuilderTest::building_the_verifier_returns_instance_of_jwt_verifier";i:4;s:58:"Test\Unit\JwtVerifierTest::can_get_issuer_from_constructor";i:4;s:61:"Test\Unit\JwtVerifierTest::can_get_discovery_from_constructor";i:4;s:72:"Test\Unit\JwtVerifierTest::will_get_meta_data_from_issuer_and_well_known";i:4;s:74:"Test\Unit\JwtVerifierBuilderTest::build_throws_exception_if_issuer_not_set";i:3;s:114:"Test\Unit\Server\DefaultServerTest::will_throw_exception_when_meta_data_is_not_json_string with data set "integer"";i:3;s:111:"Test\Unit\Server\DefaultServerTest::will_throw_exception_when_meta_data_is_not_json_string with data set "null"";i:3;s:112:"Test\Unit\Server\DefaultServerTest::will_throw_exception_when_meta_data_is_not_json_string with data set "array"";i:3;s:113:"Test\Unit\Server\DefaultServerTest::will_throw_exception_when_meta_data_is_not_json_string with data set "object"";i:3;s:65:"Test\Unit\Server\DefaultServerTest::will_get_jwks_from_well_known";i:3;s:52:"Test\Unit\JwtVerifierTest::defaults_to_oauth_adaptor";i:3;s:49:"Test\Unit\JwtVerifierTest::can_verify_empty_token";i:3;s:43:"Test\Unit\JwtVerifierTest::can_verify_nonce";i:4;s:46:"Test\Unit\JwtVerifierTest::can_verify_audience";i:3;s:51:"Test\Unit\Adaptor\FirebasePhpJwtTest::can_parse_key";i:5;s:52:"Test\Unit\Adaptor\FirebasePhpJwtTest::can_parse_keys";i:3;s:48:"Test\Unit\Adaptor\FirebasePhpJwtTest::can_decode";i:4;}s:5:"times";a:44:{s:73:"Test\Unit\Discovery\DefaultDiscoveryMethodTest::sets_well_known_correctly";d:0.002;s:56:"Test\Unit\Discovery\OauthTest::sets_well_known_correctly";d:0;s:55:"Test\Unit\Discovery\OidcTest::sets_well_known_correctly";d:0;s:70:"Test\Unit\JwtVerifierBuilderTest::when_setting_issuer_self_is_returned";d:0;s:73:"Test\Unit\JwtVerifierBuilderTest::when_setting_discovery_self_is_returned";d:0.004;s:94:"Test\Unit\JwtVerifierBuilderTest::building_the_jwt_verifier_throws_exception_if_issuer_not_set";d:0;s:75:"Test\Unit\JwtVerifierBuilderTest::discovery_defaults_to_oauth_when_building";d:0;s:88:"Test\Unit\JwtVerifierBuilderTest::building_the_verifier_returns_instance_of_jwt_verifier";d:0.006;s:58:"Test\Unit\JwtVerifierTest::can_get_issuer_from_constructor";d:0.002;s:61:"Test\Unit\JwtVerifierTest::can_get_discovery_from_constructor";d:0;s:72:"Test\Unit\JwtVerifierTest::will_get_meta_data_from_issuer_and_well_known";d:0.003;s:56:"Test\Unit\RequestTest::makes_request_to_correct_location";d:0.004;s:67:"Test\Unit\RequestTest::makes_request_to_correct_location_with_query";d:0.001;s:74:"Test\Unit\JwtVerifierBuilderTest::build_throws_exception_if_issuer_not_set";d:0.001;s:92:"Test\Unit\JwtVerifierBuilderTest::build_throws_exception_if_issuer_does_not_start_with_https";d:0;s:87:"Test\Unit\JwtVerifierBuilderTest::build_throws_exception_if_issuer_contains_replacement";d:0;s:90:"Test\Unit\JwtVerifierBuilderTest::build_throws_exception_if_client_id_contains_replacement";d:0;s:71:"Test\Unit\JwtVerifierBuilderTest::trailing_slash_is_trimmed_from_issuer";d:0.008;s:71:"Test\Unit\JwtVerifierBuilderTest::when_setting_adaptor_self_is_returned";d:0.001;s:72:"Test\Unit\JwtVerifierBuilderTest::when_setting_audience_self_is_returned";d:0;s:73:"Test\Unit\JwtVerifierBuilderTest::when_setting_client_id_self_is_returned";d:0;s:72:"Test\Unit\JwtVerifierBuilderTest::when_setting_nonce_id_self_is_returned";d:0;s:77:"Test\Unit\JwtVerifierBuilderTest::build_throws_exception_if_client_id_not_set";d:0;s:81:"Test\Unit\Server\DefaultServerTest::will_get_meta_data_from_issuer_and_well_known";d:0.003;s:114:"Test\Unit\Server\DefaultServerTest::will_throw_exception_when_meta_data_is_not_json_string with data set "integer"";d:0.001;s:111:"Test\Unit\Server\DefaultServerTest::will_throw_exception_when_meta_data_is_not_json_string with data set "null"";d:0.002;s:112:"Test\Unit\Server\DefaultServerTest::will_throw_exception_when_meta_data_is_not_json_string with data set "array"";d:0.001;s:113:"Test\Unit\Server\DefaultServerTest::will_throw_exception_when_meta_data_is_not_json_string with data set "object"";d:0.002;s:65:"Test\Unit\Server\DefaultServerTest::will_get_jwks_from_well_known";d:0.002;s:58:"Test\Unit\JwtVerifierTest::can_get_server_from_constructor";d:0.004;s:67:"Test\Unit\Server\DefaultServerTest::can_get_issuer_from_constructor";d:0.001;s:70:"Test\Unit\Server\DefaultServerTest::can_get_discovery_from_constructor";d:0;s:119:"Test\Unit\Server\DefaultServerTest::will_throw_exception_when_meta_data_is_not_json_string with data set "invalid json"";d:0.001;s:124:"Test\Unit\Server\DefaultServerTest::will_throw_exception_when_meta_data_is_not_json_string with data set "not a json object"";d:0.001;s:52:"Test\Unit\JwtVerifierTest::defaults_to_oauth_adaptor";d:0.013;s:55:"Test\Unit\JwtVerifierTest::defaults_to_firebase_adaptor";d:0.012;s:49:"Test\Unit\JwtVerifierTest::can_verify_empty_token";d:0.015;s:72:"Test\Unit\JwtVerifierTest::can_verify_empty_token_with_claims_registered";d:0.016;s:43:"Test\Unit\JwtVerifierTest::can_verify_nonce";d:0.014;s:46:"Test\Unit\JwtVerifierTest::can_verify_audience";d:0.019;s:47:"Test\Unit\JwtVerifierTest::can_verify_client_id";d:0.014;s:51:"Test\Unit\Adaptor\FirebasePhpJwtTest::can_parse_key";d:8.857;s:52:"Test\Unit\Adaptor\FirebasePhpJwtTest::can_parse_keys";d:2.472;s:48:"Test\Unit\Adaptor\FirebasePhpJwtTest::can_decode";d:0.004;}}}
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ FROM php:7.2-cli-stretch

COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer

RUN apt-get update
RUN apt-get install -y zip git

RUN pecl install xdebug-2.9.8 && docker-php-ext-enable xdebug

COPY . /app
WORKDIR /app

Expand Down
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ To validate a JWT, you will need a few different items:
require_once("/vendor/autoload.php"); // This should be replaced with your path to your vendor/autoload.php file

$jwtVerifier = (new \Okta\JwtVerifier\JwtVerifierBuilder())
->setDiscovery(new \Okta\JwtVerifier\Discovery\Oauth) // This is not needed if using oauth. The other option is `new \Okta\JwtVerifier\Discovery\OIDC`
->setAdaptor(new \Okta\JwtVerifier\Adaptors\FirebasePhpJwt)
->setDiscovery(new \Okta\JwtVerifier\Server\Discovery\Oauth) // This is not needed if using oauth. The other option is `new \Okta\JwtVerifier\Server\Discovery\OIDC`
->setAdaptor(new \Okta\JwtVerifier\Adaptor\FirebasePhpJwt)
->setAudience('api://default')
->setClientId('{clientId}')
->setIssuer('https://{yourOktaDomain}.com/oauth2/default')
Expand Down Expand Up @@ -87,8 +87,6 @@ The result from the verify method is a `Jwt` object which has a few helper metho
```php
dump($jwt); //Returns instance of \Okta\JwtVerifier\JWT

dump($jwt->toJson()); // Returns Claims as JSON Object

dump($jwt->getClaims()); // Returns Claims as they come from the JWT Package used

dump($jwt->getIssuedAt()); // returns Carbon instance of issued at time
Expand Down
7 changes: 6 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
"Okta\\JwtVerifier\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Test\\": "tests/"
}
},
"require": {
"php": "^7.2",
"ext-json": "*",
Expand All @@ -27,7 +32,7 @@
"bretterer/iso_duration_converter": "^0.1.0"
},
"require-dev": {
"phpunit/phpunit": "^7.0 ",
"phpunit/phpunit": "^8.0 ",
"symfony/var-dumper": "^5.1",
"squizlabs/php_codesniffer": "^3.5",
"php-http/mock-client": "^1.4",
Expand Down
Loading

0 comments on commit 6449d31

Please sign in to comment.