From bec7d46727810ce96d3afc923bccbd96ed08d9a5 Mon Sep 17 00:00:00 2001 From: romanetar Date: Thu, 26 Sep 2024 18:57:18 +0200 Subject: [PATCH 1/4] feat: add scopes list to otp email if it has a client Signed-off-by: romanetar --- app/Mail/OAuth2PasswordlessOTPMail.php | 11 +++++- .../OTP/OTPChannelEmailStrategy.php | 3 +- .../emails/oauth2_passwordless_otp.blade.php | 38 +++++++++++++++++++ 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/app/Mail/OAuth2PasswordlessOTPMail.php b/app/Mail/OAuth2PasswordlessOTPMail.php index 30b9f2c6..f2a939b2 100644 --- a/app/Mail/OAuth2PasswordlessOTPMail.php +++ b/app/Mail/OAuth2PasswordlessOTPMail.php @@ -16,6 +16,7 @@ use Illuminate\Queue\SerializesModels; use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Log; +use Models\OAuth2\Client; /** * Class OAuth2PasswordlessOTPMail @@ -59,18 +60,25 @@ class OAuth2PasswordlessOTPMail extends Mailable */ public $reset_password_link_lifetime; + /** + * @var Client|null + */ + public $client; + /** * @param string $to * @param string $otp * @param int $lifetime * @param string|null $reset_password_link + * @param Client|null $client */ public function __construct ( string $to, string $otp, int $lifetime, - string $reset_password_link = null + string $reset_password_link = null, + ?Client $client = null ) { $this->email = trim($to); @@ -78,6 +86,7 @@ public function __construct $this->lifetime = $lifetime / 60; $this->reset_password_link = $reset_password_link; $this->reset_password_link_lifetime = Config::get("auth.password_reset_lifetime")/60; + $this->client = $client; } /** * Build the message. diff --git a/app/Strategies/OTP/OTPChannelEmailStrategy.php b/app/Strategies/OTP/OTPChannelEmailStrategy.php index 414ea38e..446b6e26 100644 --- a/app/Strategies/OTP/OTPChannelEmailStrategy.php +++ b/app/Strategies/OTP/OTPChannelEmailStrategy.php @@ -82,7 +82,8 @@ public function send(IOTPTypeBuilderStrategy $typeBuilderStrategy, OAuth2OTP $ot $otp->getUserName(), $value, $otp->getLifetime(), - $reset_password_link + $reset_password_link, + $otp->hasClient() ? $otp->getClient() : null ) ); } diff --git a/resources/views/emails/oauth2_passwordless_otp.blade.php b/resources/views/emails/oauth2_passwordless_otp.blade.php index 9c13a7dc..2bf8924d 100644 --- a/resources/views/emails/oauth2_passwordless_otp.blade.php +++ b/resources/views/emails/oauth2_passwordless_otp.blade.php @@ -37,6 +37,44 @@ @endif + @if(!is_null($client)) + + + +
+
+ {!! $client->getApplicationName() !!} +
+
+ + + + +
+ This app would like to: +
+ + + + + + + + + +
+ ** {!! $client->getApplicationName() !!} Application and {!! Config::get("app.tenant_name") !!} will use this information in accordance with their respective terms of service and privacy policies. +
+
+ + + @endif
Thanks!

{{Config::get('app.tenant_name')}} Support Team
From 6d720d71a3c31fc2b6d3459795c500e652c8e3ad Mon Sep 17 00:00:00 2001 From: romanetar Date: Thu, 26 Sep 2024 19:41:51 +0200 Subject: [PATCH 2/4] fix: add ToS and privacy policies links Signed-off-by: romanetar --- .../views/emails/oauth2_passwordless_otp.blade.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/resources/views/emails/oauth2_passwordless_otp.blade.php b/resources/views/emails/oauth2_passwordless_otp.blade.php index 2bf8924d..676b6ba1 100644 --- a/resources/views/emails/oauth2_passwordless_otp.blade.php +++ b/resources/views/emails/oauth2_passwordless_otp.blade.php @@ -21,11 +21,6 @@
Code is valid for {{$lifetime}} minutes.
- - -
If you didn't request this, you can ignore this email.
- - @if(!empty($reset_password_link)) @@ -69,12 +64,17 @@
- ** {!! $client->getApplicationName() !!} Application and {!! Config::get("app.tenant_name") !!} will use this information in accordance with their respective terms of service and privacy policies. + ** {!! $client->getApplicationName() !!} Application and {!! Config::get("app.tenant_name") !!} will use this information in accordance with their respective terms of service and privacy policies.

@endif + + +
If you didn't request this, you can ignore this email.
+ +
Thanks!

{{Config::get('app.tenant_name')}} Support Team
From 3740f8e4867c01d9dc09225b4d8f4d81ca02db77 Mon Sep 17 00:00:00 2001 From: romanetar Date: Thu, 26 Sep 2024 20:18:46 +0200 Subject: [PATCH 3/4] fix: exploding mail-related entities into primitive parameters Signed-off-by: romanetar --- app/Mail/OAuth2PasswordlessOTPMail.php | 34 ++++++++++++++++--- .../OTP/OTPChannelEmailStrategy.php | 18 +++++++++- .../emails/oauth2_passwordless_otp.blade.php | 11 +++--- 3 files changed, 51 insertions(+), 12 deletions(-) diff --git a/app/Mail/OAuth2PasswordlessOTPMail.php b/app/Mail/OAuth2PasswordlessOTPMail.php index f2a939b2..71404dbd 100644 --- a/app/Mail/OAuth2PasswordlessOTPMail.php +++ b/app/Mail/OAuth2PasswordlessOTPMail.php @@ -61,16 +61,34 @@ class OAuth2PasswordlessOTPMail extends Mailable public $reset_password_link_lifetime; /** - * @var Client|null + * @var string|null + */ + public $client_app_name; + + /** + * @var string|null + */ + public $client_terms_of_services_uri; + + /** + * @var string|null + */ + public $client_policy_uri; + + /** + * @var string|null */ - public $client; + public $client_scope_descriptions; /** * @param string $to * @param string $otp * @param int $lifetime * @param string|null $reset_password_link - * @param Client|null $client + * @param string|null $client_app_name + * @param string|null $client_terms_of_services_uri + * @param string|null $client_policy_uri + * @param array|null $client_scope_descriptions */ public function __construct ( @@ -78,7 +96,10 @@ public function __construct string $otp, int $lifetime, string $reset_password_link = null, - ?Client $client = null + string $client_app_name = null, + string $client_terms_of_services_uri = null, + string $client_policy_uri = null, + ?array $client_scope_descriptions = [] ) { $this->email = trim($to); @@ -86,7 +107,10 @@ public function __construct $this->lifetime = $lifetime / 60; $this->reset_password_link = $reset_password_link; $this->reset_password_link_lifetime = Config::get("auth.password_reset_lifetime")/60; - $this->client = $client; + $this->client_app_name = $client_app_name; + $this->client_terms_of_services_uri = $client_terms_of_services_uri; + $this->client_policy_uri = $client_policy_uri; + $this->client_scope_descriptions = $client_scope_descriptions; } /** * Build the message. diff --git a/app/Strategies/OTP/OTPChannelEmailStrategy.php b/app/Strategies/OTP/OTPChannelEmailStrategy.php index 446b6e26..348a3455 100644 --- a/app/Strategies/OTP/OTPChannelEmailStrategy.php +++ b/app/Strategies/OTP/OTPChannelEmailStrategy.php @@ -75,6 +75,19 @@ public function send(IOTPTypeBuilderStrategy $typeBuilderStrategy, OAuth2OTP $ot $reset_password_link = $request->getResetLink(); } + $client_app_name = null; + $client_terms_of_services_uri = null; + $client_policy_uri = null; + $client_scope_descriptions = null; + + if ($otp->hasClient()) { + $client = $otp->getClient(); + $client_app_name = $client->getApplicationName(); + $client_terms_of_services_uri = $client->getTermOfServiceUri(); + $client_policy_uri = $client->getPolicyUri(); + $client_scope_descriptions = array_map(function($scope) { return $scope->getShortDescription(); }, $client->getClientScopes()); + } + Mail::queue ( new OAuth2PasswordlessOTPMail @@ -83,7 +96,10 @@ public function send(IOTPTypeBuilderStrategy $typeBuilderStrategy, OAuth2OTP $ot $value, $otp->getLifetime(), $reset_password_link, - $otp->hasClient() ? $otp->getClient() : null + $client_app_name, + $client_terms_of_services_uri, + $client_policy_uri, + $client_scope_descriptions ) ); } diff --git a/resources/views/emails/oauth2_passwordless_otp.blade.php b/resources/views/emails/oauth2_passwordless_otp.blade.php index 676b6ba1..b5a59fdf 100644 --- a/resources/views/emails/oauth2_passwordless_otp.blade.php +++ b/resources/views/emails/oauth2_passwordless_otp.blade.php @@ -32,13 +32,12 @@ @endif - @if(!is_null($client)) - + @if(!is_null($client_app_name))
- {!! $client->getApplicationName() !!} + {!! $client_app_name !!}

@@ -53,9 +52,9 @@
    - @foreach($client->getClientScopes() as $scope) + @foreach($client_scope_descriptions as $client_scope_description)
  • - {!! $scope->getShortDescription() !!} + {!! $client_scope_description !!}
  • @endforeach
@@ -64,7 +63,7 @@
- ** {!! $client->getApplicationName() !!} Application and {!! Config::get("app.tenant_name") !!} will use this information in accordance with their respective terms of service and privacy policies. + ** {!! $client_app_name !!} Application and {!! Config::get("app.tenant_name") !!} will use this information in accordance with their respective terms of service and privacy policies.

From 2af75e47886c9299343d4415666473a39b48afd4 Mon Sep 17 00:00:00 2001 From: romanetar Date: Tue, 14 Jan 2025 15:26:17 +0100 Subject: [PATCH 4/4] fix: remove non-used references Signed-off-by: romanetar --- app/Mail/OAuth2PasswordlessOTPMail.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/Mail/OAuth2PasswordlessOTPMail.php b/app/Mail/OAuth2PasswordlessOTPMail.php index 71404dbd..7f6e932a 100644 --- a/app/Mail/OAuth2PasswordlessOTPMail.php +++ b/app/Mail/OAuth2PasswordlessOTPMail.php @@ -16,7 +16,6 @@ use Illuminate\Queue\SerializesModels; use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Log; -use Models\OAuth2\Client; /** * Class OAuth2PasswordlessOTPMail