diff --git a/includes/class-token-user.php b/includes/class-token-user.php index 2769550..31c803f 100644 --- a/includes/class-token-user.php +++ b/includes/class-token-user.php @@ -190,6 +190,7 @@ public function get( $key, $hash = true ) { } $value['user'] = $user_id; + $value['sub'] = $value['me']; return $value; } diff --git a/tests/test-introspection-endpoint.php b/tests/test-introspection-endpoint.php index 0117088..ad8d2f8 100644 --- a/tests/test-introspection-endpoint.php +++ b/tests/test-introspection-endpoint.php @@ -43,6 +43,7 @@ public static function wpSetUpBeforeClass( $factory ) { ); static::$test_auth_code['me'] = get_author_posts_url( static::$author_id ); static::$test_token['me'] = get_author_posts_url( static::$author_id ); + static::$test_token['sub'] = static::$test_token['me']; static::$refresh_token['me'] = get_author_posts_url( static::$author_id ); static::$subscriber_id = $factory->user->create( array( diff --git a/tests/test-revocation-endpoint.php b/tests/test-revocation-endpoint.php index 6332205..ef69b04 100644 --- a/tests/test-revocation-endpoint.php +++ b/tests/test-revocation-endpoint.php @@ -43,6 +43,7 @@ public static function wpSetUpBeforeClass( $factory ) { ); static::$test_auth_code['me'] = get_author_posts_url( static::$author_id ); static::$test_token['me'] = get_author_posts_url( static::$author_id ); + static::$test_token['sub'] = static::$test_token['me']; static::$refresh_token['me'] = get_author_posts_url( static::$author_id ); static::$subscriber_id = $factory->user->create( array( diff --git a/tests/test-token-endpoint.php b/tests/test-token-endpoint.php index 31dfa39..cbe2a19 100644 --- a/tests/test-token-endpoint.php +++ b/tests/test-token-endpoint.php @@ -43,6 +43,7 @@ public static function wpSetUpBeforeClass( $factory ) { ); static::$test_auth_code['me'] = get_author_posts_url( static::$author_id ); static::$test_token['me'] = get_author_posts_url( static::$author_id ); + static::$test_token['sub'] = static::$test_token['me']; static::$refresh_token['me'] = get_author_posts_url( static::$author_id ); static::$subscriber_id = $factory->user->create( array( diff --git a/tests/test-tokens.php b/tests/test-tokens.php index 2c86be7..3d33979 100644 --- a/tests/test-tokens.php +++ b/tests/test-tokens.php @@ -4,10 +4,11 @@ class TokensTest extends WP_UnitTestCase { public function test_set_and_get_user_token() { $user_id = self::factory()->user->create(); $tokens = new Token_User( '_indieauth_code_', $user_id ); - $token = array( 'foo' => 'foo', 'bar' => 'bar' ); + $token = array( 'foo' => 'foo', 'bar' => 'bar', 'me' => 'https://example.com' ); $key = $tokens->set( $token ); $get = $tokens->get( $key ); unset( $get['user'] ); + $token['sub'] = $token['me']; $this->assertEquals( $token, $get ); } @@ -15,7 +16,7 @@ public function test_find_token_users() { $user_id_1 = self::factory()->user->create(); $user_id_2 = self::factory()->user->create(); $tokens = new Token_User( '_indieauth_code_', $user_id_1 ); - $token = array( 'foo' => 'foo', 'bar' => 'bar' ); + $token = array( 'foo' => 'foo', 'bar' => 'bar', 'me' => 'https://example.com' ); $tokens->set( $token ); $tokens->set_user( $user_id_2 ); $key = $tokens->set( $token ); @@ -27,7 +28,7 @@ public function test_find_by_uuid() { $user_id_1 = self::factory()->user->create(); $tokens = new Token_User( '_indieauth_code_', $user_id_1 ); $uuid = wp_generate_uuid4(); - $token = array( 'foo' => 'foo', 'bar' => 'bar', 'uuid' => $uuid ); + $token = array( 'foo' => 'foo', 'bar' => 'bar', 'me' => 'https://example.com', 'uuid' => $uuid ); $access_token = $tokens->set( $token ); $return = $tokens->find_by_field( 'uuid', $uuid, $user_id_1 ); $first = reset( $return ); @@ -39,7 +40,7 @@ public function test_find_by_uuid() { public function test_expired_token() { $user_id = self::factory()->user->create(); $tokens = new Token_User( '_indieauth_code_', $user_id ); - $token = array( 'foo' => 'foo', 'bar' => 'bar' ); + $token = array( 'foo' => 'foo', 'bar' => 'bar', 'me' => 'https://example.com' ); $key = $tokens->set( $token, -30 ); $get = $tokens->get( $key ); $this->assertFalse( $get ); @@ -48,11 +49,12 @@ public function test_expired_token() { public function test_destroy_token() { $user_id = self::factory()->user->create(); $tokens = new Token_User( '_indieauth_code_', $user_id ); - $token = array( 'foo' => 'foo', 'bar' => 'bar' ); + $token = array( 'foo' => 'foo', 'bar' => 'bar', 'me' => 'https://example.com' ); $key = $tokens->set( $token, 300 ); $get = $tokens->get( $key ); unset( $get['user'] ); unset( $get['exp' ] ); + $token['sub'] = $token['me']; $this->assertEquals( $get, $token ); $destroy = $tokens->destroy( $key ); $this->assertTrue( $destroy );