-
Notifications
You must be signed in to change notification settings - Fork 0
modified Login logic #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
3a2a059
16ad664
4693ef9
afde1dd
e3e90c7
5e2da96
a5e4359
70b206d
ce5c7d9
1038abf
cbd1d42
2d47ae2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"php":"8.3.6","version":"3.68.0:v3.68.0#73f78d8b2b34a0dd65fedb434a602ee4c2c8ad4c","indent":" ","lineEnding":"\n","rules":{"binary_operator_spaces":{"default":"at_least_single_space"},"blank_line_after_opening_tag":true,"blank_line_between_import_groups":true,"blank_lines_before_namespace":true,"braces_position":{"allow_single_line_empty_anonymous_classes":true},"class_definition":{"inline_constructor_arguments":false,"space_before_parenthesis":true},"compact_nullable_type_declaration":true,"declare_equal_normalize":true,"lowercase_cast":true,"lowercase_static_reference":true,"new_with_parentheses":true,"no_blank_lines_after_class_opening":true,"no_extra_blank_lines":{"tokens":["use"]},"no_leading_import_slash":true,"no_whitespace_in_blank_line":true,"ordered_class_elements":{"order":["use_trait"]},"ordered_imports":{"imports_order":["class","function","const"],"sort_algorithm":"none"},"return_type_declaration":true,"short_scalar_cast":true,"single_import_per_statement":{"group_to_single_imports":false},"single_space_around_construct":{"constructs_followed_by_a_single_space":["abstract","as","case","catch","class","const_import","do","else","elseif","final","finally","for","foreach","function","function_import","if","insteadof","interface","namespace","new","private","protected","public","static","switch","trait","try","use","use_lambda","while"],"constructs_preceded_by_a_single_space":["as","else","elseif","use_lambda"]},"single_trait_insert_per_statement":true,"ternary_operator_spaces":true,"unary_operator_spaces":{"only_dec_inc":true},"visibility_required":true,"blank_line_after_namespace":true,"constant_case":true,"control_structure_braces":true,"control_structure_continuation_position":true,"elseif":true,"function_declaration":true,"indentation_type":true,"line_ending":true,"lowercase_keywords":true,"method_argument_space":{"attribute_placement":"ignore","on_multiline":"ensure_fully_multiline"},"no_break_comment":true,"no_closing_tag":true,"no_multiple_statements_per_line":true,"no_space_around_double_colon":true,"no_spaces_after_function_name":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":{"elements":["property"]},"single_line_after_imports":true,"spaces_inside_parentheses":true,"statement_indentation":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"encoding":true,"full_opening_tag":true,"strict_param":true},"hashes":{"tests\/Unit\/Neo4jExceptionUnitTest.php":"0d7842780eeb9729d501831ee55df0d8","tests\/Unit\/ResultRowTest.php":"f5ee9f21d2439793a290e8ab946a7f32","tests\/Unit\/Neo4jQueryAPIUnitTest.php":"54be7f7b0f9dcf13d62c4912127583b9","tests\/Integration\/Neo4jQueryAPIIntegrationTest.php":"44977ffd6c09c505b00c8ef4857b8bfd","tests\/Integration\/Neo4jOGMTest.php":"73136b2d28fbb4fa298467d1ab3e18c8","src\/OGM.php":"93aae9c7afc8dbfd5aa00bc1d264ad19","src\/Results\/ResultRow.php":"ad55ec1bd999a8f6ad6b18874c4017b5","src\/Results\/ResultSet.php":"5f7748a356bf0fb30403e3c5a411bd24","src\/Exception\/Neo4jException.php":"dfb0f6933b9d3913c5495ba6d801d5f1","src\/Objects\/Path.php":"88c95962a6316ba7aa2fa3f0f6e31627","src\/Objects\/Node.php":"4a8ab7b8bd1981ee4d35d8c52b81c7c3","src\/Objects\/ProfiledQueryPlanArguments.php":"1be7b230a034a72c13349a5670a34a2f","src\/Objects\/Person.php":"f2f469937660f5454761e4f31154e081","src\/Objects\/Point.php":"169715b2157e08482e420374e6ca4cc3","src\/Objects\/Bookmarks.php":"50f89ca88b2df817433ce8237ccc0f18","src\/Objects\/ResultCounters.php":"a9372c98fe7bede10cb004af30ea502f","src\/Objects\/Relationship.php":"f6347c0260780d4f5d2dc407dc97e25e","src\/Transaction.php":"e456922858b31d87b17ca47d25d58474","tests\/resources\/expected\/complex-query-profile.php":"cc2b1e7e731c30a8855d9fa368cd55f3","src\/Neo4jQueryAPI.php":"8bffb787a834b58523e89fc9e5c19fe3","src\/Objects\/ProfiledQueryPlan.php":"d9ba608f3177426ea34d73276d75f20b"}} | ||
{"php":"8.3.6","version":"3.68.0:v3.68.0#73f78d8b2b34a0dd65fedb434a602ee4c2c8ad4c","indent":" ","lineEnding":"\n","rules":{"binary_operator_spaces":{"default":"at_least_single_space"},"blank_line_after_opening_tag":true,"blank_line_between_import_groups":true,"blank_lines_before_namespace":true,"braces_position":{"allow_single_line_empty_anonymous_classes":true},"class_definition":{"inline_constructor_arguments":false,"space_before_parenthesis":true},"compact_nullable_type_declaration":true,"declare_equal_normalize":true,"lowercase_cast":true,"lowercase_static_reference":true,"new_with_parentheses":true,"no_blank_lines_after_class_opening":true,"no_extra_blank_lines":{"tokens":["use"]},"no_leading_import_slash":true,"no_whitespace_in_blank_line":true,"ordered_class_elements":{"order":["use_trait"]},"ordered_imports":{"imports_order":["class","function","const"],"sort_algorithm":"none"},"return_type_declaration":true,"short_scalar_cast":true,"single_import_per_statement":{"group_to_single_imports":false},"single_space_around_construct":{"constructs_followed_by_a_single_space":["abstract","as","case","catch","class","const_import","do","else","elseif","final","finally","for","foreach","function","function_import","if","insteadof","interface","namespace","new","private","protected","public","static","switch","trait","try","use","use_lambda","while"],"constructs_preceded_by_a_single_space":["as","else","elseif","use_lambda"]},"single_trait_insert_per_statement":true,"ternary_operator_spaces":true,"unary_operator_spaces":{"only_dec_inc":true},"visibility_required":true,"blank_line_after_namespace":true,"constant_case":true,"control_structure_braces":true,"control_structure_continuation_position":true,"elseif":true,"function_declaration":true,"indentation_type":true,"line_ending":true,"lowercase_keywords":true,"method_argument_space":{"attribute_placement":"ignore","on_multiline":"ensure_fully_multiline"},"no_break_comment":true,"no_closing_tag":true,"no_multiple_statements_per_line":true,"no_space_around_double_colon":true,"no_spaces_after_function_name":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":{"elements":["property"]},"single_line_after_imports":true,"spaces_inside_parentheses":true,"statement_indentation":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"encoding":true,"full_opening_tag":true,"strict_param":true},"hashes":{"tests\/Unit\/Neo4jExceptionUnitTest.php":"0d7842780eeb9729d501831ee55df0d8","tests\/Unit\/ResultRowTest.php":"f5ee9f21d2439793a290e8ab946a7f32","tests\/Integration\/Neo4jOGMTest.php":"73136b2d28fbb4fa298467d1ab3e18c8","src\/OGM.php":"93aae9c7afc8dbfd5aa00bc1d264ad19","src\/Results\/ResultRow.php":"ad55ec1bd999a8f6ad6b18874c4017b5","src\/Results\/ResultSet.php":"5f7748a356bf0fb30403e3c5a411bd24","src\/Exception\/Neo4jException.php":"dfb0f6933b9d3913c5495ba6d801d5f1","src\/Objects\/Path.php":"88c95962a6316ba7aa2fa3f0f6e31627","src\/Objects\/Node.php":"4a8ab7b8bd1981ee4d35d8c52b81c7c3","src\/Objects\/ProfiledQueryPlanArguments.php":"1be7b230a034a72c13349a5670a34a2f","src\/Objects\/Person.php":"f2f469937660f5454761e4f31154e081","src\/Objects\/Point.php":"169715b2157e08482e420374e6ca4cc3","src\/Objects\/Bookmarks.php":"50f89ca88b2df817433ce8237ccc0f18","src\/Objects\/ResultCounters.php":"a9372c98fe7bede10cb004af30ea502f","src\/Objects\/Relationship.php":"f6347c0260780d4f5d2dc407dc97e25e","src\/Transaction.php":"e456922858b31d87b17ca47d25d58474","tests\/resources\/expected\/complex-query-profile.php":"cc2b1e7e731c30a8855d9fa368cd55f3","src\/Objects\/ProfiledQueryPlan.php":"d9ba608f3177426ea34d73276d75f20b","tests\/Unit\/AuthenticationTest.php":"e4fb1f55a984d75f229102ddf6a9350f","src\/Objects\/Authentication.php":"ea428c99aae634b69a5843fe523a016d","src\/Objects\/php your-script.php":"63c3a9abbf4774d1da8c5f3c9f8f455e","tests\/Unit\/Neo4jQueryAPIUnitTest.php":"cea0eed7cb66b5d5dec405d6f83c0669","tests\/Integration\/Neo4jQueryAPIIntegrationTest.php":"c04106facdd3b520cabe5e8b8c74ca10","src\/Neo4jQueryAPI.php":"8c57c191311e777d37b83eb63f624fb2"}} | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
namespace Neo4j\QueryAPI\Objects; | ||
|
||
use InvalidArgumentException; | ||
|
||
class Authentication | ||
{ | ||
private string $header; | ||
private string $type; | ||
|
||
private function __construct(string $header, string $type) | ||
{ | ||
$this->header = $header; | ||
$this->type = $type; | ||
} | ||
|
||
public static function request(string $username = null, string $password = null, string $token = null): self | ||
|
||
{ | ||
if ($token !== null) { | ||
return self::bearer($token); | ||
} | ||
if ($username === null) { | ||
$username = getenv('NEO4J_USERNAME'); | ||
} | ||
|
||
if ($password === null) { | ||
$password = getenv('NEO4J_PASSWORD'); | ||
} | ||
if ($username !== null && $password !== null) { | ||
return self::basic($username, $password); | ||
} | ||
|
||
throw new InvalidArgumentException("Both username and password cannot be null."); | ||
} | ||
|
||
private static function basic(string $username, string $password): self | ||
{ | ||
return new self("Basic " . base64_encode("$username:$password"), 'Basic'); | ||
} | ||
|
||
private static function bearer(string $token): self | ||
{ | ||
return new self("Bearer $token", 'Bearer'); | ||
} | ||
|
||
public function getHeader(): string | ||
{ | ||
return $this->header; // Return the header string directly | ||
} | ||
|
||
public function getType(): string | ||
{ | ||
return $this->type; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
use Neo4j\QueryAPI\Objects\Authentication; | ||
|
||
|
||
require_once 'Authentication.php'; // Assuming your Authentication class is in Authentication.php | ||
|
||
// Using Bearer Token Authentication | ||
$authBearer = Authentication::create([ | ||
'token' => 'yourBearerToken' | ||
]); | ||
|
||
print_r($authBearer->getHeader()); | ||
|
||
// Using Basic Authentication | ||
$authBasic = Authentication::create([ | ||
'username' => '', | ||
'password' => '' | ||
]); | ||
|
||
print_r($authBasic->getHeader()); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
namespace Neo4j\QueryAPI\Tests\Unit; | ||
|
||
use Neo4j\QueryAPI\Objects\Authentication; | ||
use PHPUnit\Framework\TestCase; | ||
use InvalidArgumentException; | ||
|
||
class AuthenticationTest extends TestCase | ||
{ | ||
public function testBearerToken(): void | ||
{ | ||
// Mock a bearer token | ||
$mockToken = 'mocked_bearer_token'; | ||
|
||
// Create an Authentication instance with the bearer token | ||
$auth = Authentication::request(token: $mockToken); | ||
|
||
// Assert that the Authorization header is correct | ||
$this->assertEquals("Bearer $mockToken", $auth->getHeader(), 'Bearer token mismatch.'); | ||
$this->assertEquals('Bearer', $auth->getType(), 'Type should be Bearer.'); | ||
} | ||
|
||
public function testBasicAuthentication(): void | ||
{ | ||
// Mock username and password | ||
$mockUsername = 'mockUser'; | ||
$mockPassword = 'mockPass'; | ||
|
||
// Create an Authentication instance with username and password | ||
$auth = Authentication::request($mockUsername, $mockPassword); | ||
|
||
// Assert that the Authorization header is correct | ||
$expectedHeader = 'Basic ' . base64_encode("$mockUsername:$mockPassword"); | ||
$this->assertEquals($expectedHeader, $auth->getHeader(), 'Basic authentication header mismatch.'); | ||
$this->assertEquals('Basic', $auth->getType(), 'Type should be Basic.'); | ||
} | ||
|
||
public function testFallbackToEnvironmentVariables(): void | ||
{ | ||
// Mock environment variables | ||
putenv('NEO4J_USERNAME=mockEnvUser'); | ||
putenv('NEO4J_PASSWORD=mockEnvPass'); | ||
|
||
// Create an Authentication instance with environment variables | ||
$auth = Authentication::request(); | ||
|
||
// Assert that the Authorization header is correct | ||
$expectedHeader = 'Basic ' . base64_encode("mockEnvUser:mockEnvPass"); | ||
$this->assertEquals($expectedHeader, $auth->getHeader(), 'Basic authentication with environment variables mismatch.'); | ||
$this->assertEquals('Basic', $auth->getType(), 'Type should be Basic.'); | ||
|
||
// Cleanup the environment variables | ||
|
||
putenv('NEO4J_USERNAME'); | ||
putenv('NEO4J_PASSWORD'); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please remove this from git history. You can do this by adding the file to
.gitignore
and then runninggit rm --cached .php-cs-fixer.cache