Skip to content

Commit a53c106

Browse files
authored
Merge pull request #442 from datamweb/fix-error-if-set-authenticatorHeader
fix: correct display of the error in case of change `authenticatorHeader`
2 parents 6bafe05 + 3df1b85 commit a53c106

File tree

12 files changed

+18
-10
lines changed

12 files changed

+18
-10
lines changed

docs/guides/api_tokens.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
Access Tokens can be used to authenticate users for your own site, or when allowing third-party developers to access your API. When making requests using access tokens, the token should be included in the `Authorization` header as a `Bearer` token.
44

5+
> **Note** By default, `$authenticatorHeader['tokens']` is set to `Authorization`. You can change this value by setting the `$authenticatorHeader['tokens']` value in the `Auth.php` config file.
6+
57
Tokens are issued with the `generateAccessToken()` method on the user. This returns a `CodeIgniter\Shield\Entities\AccessToken` instance. Tokens are hashed using a SHA-256 algorithm before being saved to the database. The access token returned when you generate it will include a `raw_token` field that contains the plain-text, un-hashed, token. You should display this to your user at once so they have a chance to copy it somewhere safe, as this is the only time this will be available. After this request, there is no way to get the raw token.
68

79
The `generateAccessToken()` method requires a name for the token. These are free strings and are often used to identify the user/device the token was generated from, like 'Johns MacBook Air'.

docs/guides/mobile_apps.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,9 @@ class LoginController extends BaseController
5858
```
5959

6060
When making all future requests to the API, the mobile client should return the raw token in the `Authorization` header as a `Bearer` token.
61+
62+
> **Note**
63+
>
64+
> By default, `$authenticatorHeader['tokens']` is set to `Authorization`. You can change the header name by setting the `$authenticatorHeader['tokens']` value in the `Auth.php` config file.
65+
>
66+
> e.g. if `$authenticatorHeader['tokens']` is set to `PersonalAccessCodes` then the mobile client should return the raw token in the `PersonalAccessCodes` header as a `Bearer` token.

src/Authentication/Authenticators/AccessTokens.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function check(array $credentials): Result
9595
if (! array_key_exists('token', $credentials) || empty($credentials['token'])) {
9696
return new Result([
9797
'success' => false,
98-
'reason' => lang('Auth.noToken'),
98+
'reason' => lang('Auth.noToken', [config('Auth')->authenticatorHeader['tokens']]),
9999
]);
100100
}
101101

src/Language/de/Auth.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
'badAttempt' => 'Sie konnten nicht angemeldet werden. Bitte überprüfen Sie Ihre Anmeldedaten.',
1313
'noPassword' => 'Kann einen Benutzer ohne Passwort nicht validieren.',
1414
'invalidPassword' => 'Sie können nicht angemeldet werden. Bitte überprüfen Sie Ihr Passwort.',
15-
'noToken' => 'Jede Anfrage muss ein Überbringer-Token im Authorization-Header enthalten.',
15+
'noToken' => 'Jede Anfrage muss ein Überbringer-Token im {0}-Header enthalten.',
1616
'badToken' => 'Das Zugriffstoken ist ungültig.',
1717
'oldToken' => 'Das Zugriffstoken ist abgelaufen.',
1818
'noUserEntity' => 'Die Benutzerentität muss für die Passwortüberprüfung angegeben werden.',

src/Language/en/Auth.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
'badAttempt' => 'Unable to log you in. Please check your credentials.',
1313
'noPassword' => 'Cannot validate a user without a password.',
1414
'invalidPassword' => 'Unable to log you in. Please check your password.',
15-
'noToken' => 'Every request must have a bearer token in the Authorization header.',
15+
'noToken' => 'Every request must have a bearer token in the {0} header.',
1616
'badToken' => 'The access token is invalid.',
1717
'oldToken' => 'The access token has expired.',
1818
'noUserEntity' => 'User Entity must be provided for password validation.',

src/Language/es/Auth.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
'badAttempt' => 'No puedes entrar. Por favor, comprueba tus creenciales.',
1313
'noPassword' => 'No se puede validar un usuario sin una contraseña.',
1414
'invalidPassword' => 'No uedes entrar. Por favor, comprueba tu contraseña.',
15-
'noToken' => 'Cada petición debe tenerun token en la Authorización.',
15+
'noToken' => 'Cada petición debe tenerun token en la {0}.',
1616
'badToken' => 'Token de acceso no válido.',
1717
'oldToken' => 'El token de acceso ha caducado.',
1818
'noUserEntity' => 'Se debe dar una Entidad de Usuario para validar la contraseña.',

src/Language/fa/Auth.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
'badAttempt' => 'امکان ورود به سیستم نیست. لطفا اعتبارنامه خود را بررسی کنید.',
2222
'noPassword' => 'تایید کاربر بدون رمز عبور ممکن نیست.',
2323
'invalidPassword' => 'ناتوان در ورود به سیستم. لطفا رمز عبور خود را بررسی کنید.',
24-
'noToken' => 'هر درخواست باید دارای یک توکن bearer در هدر Authorization باشد.',
24+
'noToken' => 'هر درخواست باید دارای یک توکن bearer در هدر {0} باشد.',
2525
'badToken' => 'توکن دسترسی معتبر نمی باشد.',
2626
'oldToken' => 'توکن دسترسی منقضی شده است.',
2727
'noUserEntity' => 'برای اعتبار سنجی هویت کاربر بایستی رمز عبور ارائه شود',

src/Language/fr/Auth.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
'badAttempt' => 'Connexion impossible. Veuillez vérifier les informations saisies.',
1313
'noPassword' => 'Impossible de valider un utilisateur sans mot de passe.',
1414
'invalidPassword' => 'Connexion impossible. Veuillez vérifier votre mot de passe.',
15-
'noToken' => 'Chaque demande doit comporter un jeton d\'accès dans l\'en-tête d\'autorisation.',
15+
'noToken' => 'Chaque demande doit comporter un jeton d\'accès dans l\'en-tête d\'{0}.',
1616
'badToken' => 'Le jeton d\'accès est invalide.',
1717
'oldToken' => 'Le jeton d\'accès a expiré.',
1818
'noUserEntity' => 'User Entity doit être fournie pour la validation du mot de passe.',

src/Language/id/Auth.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
'badAttempt' => 'Anda tidak dapat masuk. Harap periksa kredensial Anda.',
1313
'noPassword' => 'Tidak dapat memvalidasi pengguna tanpa kata sandi.',
1414
'invalidPassword' => 'Anda tidak dapat masuk. Harap periksa kata sandi Anda.',
15-
'noToken' => 'Setiap permintaan harus memiliki token pembawa di header Authorization.',
15+
'noToken' => 'Setiap permintaan harus memiliki token pembawa di header {0}.',
1616
'badToken' => 'Akses token tidak sah.',
1717
'oldToken' => 'Akses token sudah tidak berlaku.',
1818
'noUserEntity' => 'Entitas Pengguna harus disediakan untuk validasi kata sandi.',

src/Language/ja/Auth.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
'badAttempt' => 'ログインできません。認証情報を確認してください。', // 'Unable to log you in. Please check your credentials.',
1313
'noPassword' => 'パスワードのないユーザーは認証できません。', // 'Cannot validate a user without a password.',
1414
'invalidPassword' => 'ログインできません。パスワードを確認してください。', // 'Unable to log you in. Please check your password.',
15-
'noToken' => 'すべてのリクエストは、AuthorizationヘッダーにBearerトークンが必要です', // 'Every request must have a bearer token in the Authorization header.',
15+
'noToken' => 'すべてのリクエストは、{0}ヘッダーにBearerトークンが必要です', // 'Every request must have a bearer token in the Authorization header.',
1616
'badToken' => 'アクセストークンが無効です。', // 'The access token is invalid.',
1717
'oldToken' => 'アクセストークンの有効期限が切れています。', // 'The access token has expired.',
1818
'noUserEntity' => 'パスワード検証のため、Userエンティティを指定する必要があります。', // 'User Entity must be provided for password validation.',

0 commit comments

Comments
 (0)