-
Notifications
You must be signed in to change notification settings - Fork 8
EPT-2965: Add authentication endpoints #83
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,10 @@ | ||
| API_URL="" | ||
|
|
||
| CLIENT_ID="" | ||
| CLIENT_SECRET="" | ||
| REFRESH_TOKEN="" | ||
|
|
||
| COCKPIT_USER_ID="" | ||
| COCKPIT_USER_NAME="" | ||
| COCKPIT_USER_EMAIL="" | ||
| COCKPIT_USER_PASSWORD="" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module BeyondApi | ||
| module Authentication | ||
| # @example How to instantiate a client | ||
| # @client = BeyondApi::Authentication::EmailAddress.new( | ||
| # api_url: 'https://example.com/api', | ||
| # access_token: 'your_token' | ||
| # ) | ||
| class EmailAddress < BaseService | ||
| # Trigger an email address change | ||
| # | ||
| # @see https://developer.epages.com/beyond-docs/#trigger_email_address_change | ||
| # | ||
| # @option params [Integer] :user_id | ||
| # @option params [String] :locale defines the language of the confirmation email is to be sent. | ||
| # @option params [String] :current_password the current password of the user account. | ||
| # @option params [String] :new_email the new email address for the user to set. | ||
| # | ||
| # @example | ||
| # @client.trigger_change( | ||
| # "9ed8418f-d568-4327-9f20-ec1d00614398", | ||
| # "en-US", | ||
| # "GoodPassword01!;)", | ||
| # "[email protected]" | ||
| # ) | ||
| def trigger_change(user_id, locale, current_password, new_email) | ||
| post( | ||
| "users/#{user_id}/change-email-request", | ||
| { current_password:, new_email: }, # body | ||
| locale # query params | ||
| ) | ||
| end | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
lib/beyond_api/services/authentication/user_and_password.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module BeyondApi | ||
| module Authentication | ||
| # @example How to instantiate a client | ||
| # @client = BeyondApi::Authentication::UserAndPassword.new( | ||
| # api_url: 'https://example.com/api', | ||
| # access_token: 'your_token' | ||
| # ) | ||
| class UserAndPassword < BaseService | ||
| # Verify a password against the password guidelines. | ||
| # | ||
| # @see https://developer.epages.com/beyond-docs/#verify_password | ||
| # | ||
| # @option params [Integer] :user_role the type of user. Can be one of merchant, support, or customer. | ||
| # @option params [String] :password the password that needs to be verified. | ||
| # | ||
| # @example | ||
| # @client.verify_password( | ||
| # "merchant", | ||
| # "ValidPassword!" | ||
| # ) | ||
| def verify_password(user_role, password) | ||
| post( | ||
| 'users/verify-password', | ||
| { password: }, # body | ||
| user_role # query params | ||
| ) | ||
| end | ||
|
|
||
| # Trigger an email address change | ||
| # | ||
| # @see https://developer.epages.com/beyond-docs/#change_password | ||
| # | ||
| # @option params [Integer] :user_id | ||
| # @option params [String] :current_password the current password of the user. This is verified before the password change. | ||
| # @option params [String] :new_password the new password to set in order to change the password. | ||
| # | ||
| # @example | ||
| # @client.change_password( | ||
| # "9ed8418f-d568-4327-9f20-ec1d00614398", | ||
| # "GoodPassword01!;)", | ||
| # "ValidPassword123" | ||
| # ) | ||
| def change_password(user_id, current_password, new_password) | ||
| post( | ||
| "users/#{user_id}/change-password", | ||
| { current_password:, new_password: } # body | ||
| ) | ||
| end | ||
|
|
||
| # Trigger an email address change | ||
| # | ||
| # @see https://developer.epages.com/beyond-docs/#trigger_password_reset_email | ||
| # | ||
| # @option params [String] :email the email address of the user account. | ||
| # | ||
| # @example | ||
| # @client.password_reset_email( | ||
| # "[email protected]" | ||
| # ) | ||
| def password_reset_email(email) | ||
| post( | ||
| 'users/reset-password-request', | ||
| { email: } # body | ||
| ) | ||
| end | ||
|
|
||
| # Change the username of a user. | ||
| # | ||
| # @see https://developer.epages.com/beyond-docs/#change_username | ||
| # | ||
| # @option params [Integer] :user_id the email address of the user account. | ||
| # @option params [String] :current_password The current password of the user. This is verified before the username change. | ||
| # @option params [String] :new_username The new username to set in order to change the username. | ||
| # | ||
| # @example | ||
| # @client.change_username( | ||
| # "9ed8418f-d568-4327-9f20-ec1d00614398", | ||
| # "ValidPassword123", | ||
| # "[email protected]" | ||
| # ) | ||
| def change_username(user_id, current_password, new_username) | ||
| post( | ||
| "users/#{user_id}/change-username", | ||
| { current_password:, new_username: }, # body | ||
| user_role # query params | ||
| ) | ||
| end | ||
| end | ||
| end | ||
| end |
22 changes: 22 additions & 0 deletions
22
spec/beyond_api/services/authentication/email_address_spec.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| RSpec.describe BeyondApi::Authentication::EmailAddress, vcr: true do | ||
| let(:client) { described_class.new(api_url: ENV.fetch('API_URL', nil), access_token: beyond_access_token) } | ||
|
|
||
| let(:user_id) { ENV.fetch('COCKPIT_USER_ID', nil) } | ||
| let(:user_email) { ENV.fetch('COCKPIT_USER_EMAIL', nil) } | ||
| let(:user_password) { ENV.fetch('COCKPIT_USER_PASSWORD', nil) } | ||
|
|
||
| let(:new_email) { '[email protected]' } | ||
|
|
||
| describe '#trigger_change' do | ||
| it 'change email address' do | ||
| # client.trigger_change(user_id, 'en-US', user_password, new_email) | ||
| end | ||
|
|
||
| after do | ||
| # # Rollback email address change | ||
| # client.trigger_change(user_id, 'en-US', user_password, user_email) | ||
| end | ||
| end | ||
| end |
66 changes: 66 additions & 0 deletions
66
spec/beyond_api/services/authentication/user_and_password_spec.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| RSpec.describe BeyondApi::Authentication::UserAndPassword, vcr: true do | ||
| let(:client) { described_class.new(api_url: ENV.fetch('API_URL', nil), access_token: beyond_access_token) } | ||
|
|
||
| let(:user_id) { ENV.fetch('COCKPIT_USER_ID', nil) } | ||
| let(:user_name) { ENV.fetch('COCKPIT_USER_NAME', nil) } | ||
| let(:user_email) { ENV.fetch('COCKPIT_USER_EMAIL', nil) } | ||
| let(:user_password) { ENV.fetch('COCKPIT_USER_PASSWORD', nil) } | ||
|
|
||
| describe '#verify_password' do | ||
| let(:new_password) { 'ValidPassword123' } | ||
|
|
||
| it 'sends a post request with the correct parameters' do | ||
| # client.verify_password('merchant', new_password) | ||
| end | ||
| end | ||
|
|
||
| describe '#change_password' do | ||
| let(:new_password) { 'ValidPassword123' } | ||
|
|
||
| it 'sends a post request with the correct parameters' do | ||
| # client.change_password( | ||
| # user_id, | ||
| # user_password, | ||
| # new_password | ||
| # ) | ||
| end | ||
|
|
||
| after do | ||
| # # Rollback the password change | ||
| # client.change_password( | ||
| # user_id, | ||
| # new_password, | ||
| # user_password | ||
| # ) | ||
| end | ||
| end | ||
|
|
||
| describe '#password_reset_email' do | ||
| it 'sends a post request with the correct parameters' do | ||
| # client.password_reset_email(user_email) | ||
| end | ||
| end | ||
|
|
||
| describe '#change_username' do | ||
| let(:new_name) { 'test-user' } | ||
|
|
||
| it 'sends a post request with the correct parameters' do | ||
| # client.change_username( | ||
| # user_id, | ||
| # user_password, | ||
| # new_name | ||
| # ) | ||
| end | ||
|
|
||
| after do | ||
| # # Rollback the username change | ||
| # client.change_username( | ||
| # user_id, | ||
| # user_password, | ||
| # user_name | ||
| # ) | ||
| end | ||
| end | ||
| end | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I would leave the tests like follows (I just put one example):
I believe that writing an
itstatement without a block displays a "Pending" message when running the tests.