Skip to content
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

Change token header name #593

Merged
merged 4 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions docs/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1076,7 +1076,7 @@
"parameters": [
{
"in": "header",
"name": "X-Auth-Token",
"name": "X-Movary-Token",
"schema": {
"type": "string"
},
Expand Down Expand Up @@ -1131,7 +1131,7 @@
"Authentication"
],
"summary": "Create authentication token",
"description": "Create an authentication token via email, password and optionally TOTP code. Add the token as X-Auth-Token header to further requests. Token lifetime 1d default, 30d with rememberMe.",
"description": "Create an authentication token via email, password and optionally TOTP code. Add the token as X-Movary-Token header to further requests. Token lifetime 1d default, 30d with rememberMe.",
"parameters": [
{
"in": "header",
Expand Down Expand Up @@ -1230,11 +1230,11 @@
"Authentication"
],
"summary": "Delete authentication token",
"description": "Delete the authentication token provided in the X-Auth-Token header value.",
"description": "Delete the authentication token provided in the X-Movary-Token header value.",
"parameters": [
{
"in": "header",
"name": "X-Auth-Token",
"name": "X-Movary-Token",
"schema": {
"type": "string"
},
Expand Down Expand Up @@ -1471,7 +1471,7 @@
"securitySchemes": {
"token": {
"type": "apiKey",
"name": "X-Auth-Token",
"name": "X-Movary-Token",
"in": "header"
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Domain/User/Service/Authentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function getToken(Request $request) : ?string
return $tokenInCookie;
}

return $request->getHeaders()['X-Auth-Token'] ?? null;
return $request->getHeaders()['X-Movary-Token'] ?? null;
}

public function getUserIdByApiToken(Request $request) : ?int
Expand Down
151 changes: 0 additions & 151 deletions tests/rest/api/authentication.assert.http

This file was deleted.

89 changes: 85 additions & 4 deletions tests/rest/api/authentication.http
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,102 @@ Cache-Control: no-cache
Content-Type: application/json
X-Movary-Client: RestAPI Test

{"email" : "{{email}}", "password" : "{{password}}", "rememberMe" : 1, "totpCode" : 123456}
{}

> {%
client.test("Response has correct status code", function() {
let expected = 400
client.assert(response.status === expected, "Expected status code: " + expected);
});
client.test("Response has correct body", function() {
let expected = '{"error":"MissingCredentials","message":"Email or password is missing"}';
client.assert(JSON.stringify(response.body) === expected, "Expected response body: " + expected);
});
%}

###

POST http://127.0.0.1/api/authentication/token
Accept: */*
Cache-Control: no-cache
Content-Type: application/json
X-Movary-Client: RestAPI Test

{"email" : "wrongEmail", "password" : "wrongPassword"}

> {%
client.test("Response has correct status code", function() {
let expected = 401
client.assert(response.status === expected, "Expected status code: " + expected);
});
client.test("Response has correct body", function() {
let expected = '{"error":"InvalidCredentials","message":"Invalid credentials"}';
client.assert(JSON.stringify(response.body) === expected, "Expected response body: " + expected);
});
%}

###

POST http://127.0.0.1/api/authentication/token
Accept: */*
Cache-Control: no-cache
Content-Type: application/json
X-Movary-Client: RestAPI Test

{"email" : "{{email}}", "password" : "{{password}}"}

> {%
client.test("Response has correct status code", function() {
let expected = 200
client.assert(response.status === expected, "Expected status code: " + expected);
});
client.test("Response has correct body", function() {
client.assert(response.body.hasOwnProperty("'userId'") === false, "Response body missing property: userId");
client.assert(response.body.hasOwnProperty("'authToken'") === false, "Response body missing property: authToken");
});

client.global.set("responseAuthToken", response.body.authToken);
%}

###

GET http://127.0.0.1/api/authentication/token
Accept: */*
Cache-Control: no-cache
Content-Type: application/json
X-Auth-Token: {{xAuthToken}}
X-Movary-Token: {{xMovaryToken}}

###

DELETE http://127.0.0.1/api/authentication/token
Accept: */*
Cache-Control: no-cache
Content-Type: application/json
X-Movary-Client: RestAPI Test
X-Auth-Token: {{xAuthToken}}
X-Movary-Token: {{responseAuthToken}}

> {%
client.test("Response has correct status code", function() {
let expected = 204
client.assert(response.status === expected, "Expected status code: " + expected);
});
%}

###

DELETE http://127.0.0.1/api/authentication/token
Accept: */*
Cache-Control: no-cache
Content-Type: application/json

> {%
client.test("Response has correct status code", function() {
let expected = 400
client.assert(response.status === expected, "Expected status code: " + expected);
});
client.test("Response has correct body", function() {
let expected = '{"error":"MissingAuthToken","message":"Authentication token header is missing"}';
client.assert(JSON.stringify(response.body) === expected, "Expected response body: " + expected);
});
%}

###
2 changes: 1 addition & 1 deletion tests/rest/api/http-client.env.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"testUser": {
"username": "testUser",
"xAuthToken": "4f0fbe93e2752932e5700e14ffa49f67",
"xMovaryToken": "4f0fbe93e2752932e5700e14ffa49f67",
"email": "[email protected]",
"password": "password1234"
}
Expand Down
2 changes: 1 addition & 1 deletion tests/rest/api/movie-search.http
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ GET http://127.0.0.1/api/movies/search?search=Matrix&page=1&releaseYear=2012
Accept: */*
Cache-Control: no-cache
Content-Type: application/json
X-Auth-Token: {{xAuthToken}}
X-Movary-Token: {{xMovaryToken}}

####
8 changes: 4 additions & 4 deletions tests/rest/api/user-history.http
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ GET http://127.0.0.1/api/users/{{username}}/history/movies?search=Matrix&limit=1
Accept: */*
Cache-Control: no-cache
Content-Type: application/json
X-Auth-Token: {{xAuthToken}}
X-Movary-Token: {{xMovaryToken}}

####

PUT http://127.0.0.1/api/users/{{username}}/history/movies
Accept: */*
Cache-Control: no-cache
Content-Type: application/json
X-Auth-Token: {{xAuthToken}}
X-Movary-Token: {{xMovaryToken}}

[{"movaryId" : 1, "watchedAt" : "2011-05-06", "plays" : 1, "comment" : "comment"}]

Expand All @@ -20,7 +20,7 @@ POST http://127.0.0.1/api/users/{{username}}/history/movies
Accept: */*
Cache-Control: no-cache
Content-Type: application/json
X-Auth-Token: {{xAuthToken}}
X-Movary-Token: {{xMovaryToken}}

[{"movaryId" : 1, "watchedAt" : "2011-05-06"}]

Expand All @@ -30,7 +30,7 @@ DELETE http://127.0.0.1/api/users/{{username}}/history/movies
Accept: */*
Cache-Control: no-cache
Content-Type: application/json
X-Auth-Token: {{xAuthToken}}
X-Movary-Token: {{xMovaryToken}}

[{"movaryId" : 1, "watchedAt" : "2011-05-06"}]

Expand Down
8 changes: 4 additions & 4 deletions tests/rest/api/user-played.http
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ GET http://127.0.0.1/api/users/{{username}}/played/movies?limit=10&sortOrder=des
Accept: */*
Cache-Control: no-cache
Content-Type: application/json
X-Auth-Token: {{xAuthToken}}
X-Movary-Token: {{xMovaryToken}}

####

PUT http://127.0.0.1/api/users/{{username}}/played/movies
Accept: */*
Cache-Control: no-cache
Content-Type: application/json
X-Auth-Token: {{xAuthToken}}
X-Movary-Token: {{xMovaryToken}}

[
{
Expand All @@ -36,7 +36,7 @@ POST http://127.0.0.1/api/users/{{username}}/played/movies
Accept: */*
Cache-Control: no-cache
Content-Type: application/json
X-Auth-Token: {{xAuthToken}}
X-Movary-Token: {{xMovaryToken}}

[
{
Expand All @@ -60,7 +60,7 @@ DELETE http://127.0.0.1/api/users/{{username}}/played/movies
Accept: */*
Cache-Control: no-cache
Content-Type: application/json
X-Auth-Token: {{xAuthToken}}
X-Movary-Token: {{xMovaryToken}}

[
{
Expand Down
Loading
Loading