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

feat: Add auth-token for batch operations #356

Merged
merged 4 commits into from
Jul 19, 2022
Merged

Conversation

YoshihitoAso
Copy link
Member

Close

close #354

Changes

New Table

auth_token

  • Table for managing authentication tokens for each issuer
# issuer address
issuer_address = Column(String(42), primary_key=True)
# authentication token (sha256 hashed)
auth_token = Column(String(64))
# usage start
usage_start = Column(DateTime, default=datetime.utcnow)
# valid duration (sec)
# - 0: endless
valid_duration = Column(Integer, nullable=False)

New API

POST: /accounts/{issuer_address}/auth_token

  • Create temporary authorization token (auth-token)

DELETE: /accounts/{issuer_address}/auth_token

  • Delete authorization token

Behavior Changed API

Authorization using auth-token is available for the following APIs, in addition to authorization using eoa-password.

POST: /bond/tokens
POST: /bond/tokens/{token_address}
POST: /bond/tokens/{token_address}/additional_issue
POST: /bond/tokens/{token_address}/redeem
POST: /bond/tokens/{token_address}/personal_info
POST: /bond/tokens/{token_address}/personal_info/batch
POST: /bond/tokens/{token_address}/holders/{account_address}/personal_info
POST: /bond/transfers
POST: /bond/bulk_transfer
POST: /bond/transfer_approvals/{token_address}/{id}

POST: /share/tokens
POST: /share/tokens/{token_address}
POST: /share/tokens/{token_address}/additional_issue
POST: /share/tokens/{token_address}/redeem
POST: /share/tokens/{token_address}/personal_info
POST: /share/tokens/{token_address}/personal_info/batch
POST: /share/tokens/{token_address}/holders/{account_address}/personal_info
POST: /share/transfers
POST: /share/bulk_transfer
POST: /share/transfer_approvals/{token_address}/{id}

Comment on lines 115 to 117
except AuthorizationError:
auth_error(request, issuer_address, "issuer does not exist")
raise AuthorizationError("issuer does not exist, or password mismatch")
Copy link
Member

@purplesmoke05 purplesmoke05 Jul 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to use raise Exception from None or raise Exception from e when re-raise Exception
because this may generate log like following.

The above exception was the direct cause of the following exception:

Alternatively, it may be better to leave error raising to each function.
(Might add more arguments for log output needed in case of authentication failure)

Comment on lines +418 to +425
if auth_token is not None:
# If a valid auth token already exists, return an error.
if auth_token.valid_duration == 0:
raise AuthTokenAlreadyExistsError()
else:
expiration_datetime = auth_token.usage_start + timedelta(seconds=auth_token.valid_duration)
if datetime.utcnow() <= expiration_datetime:
raise AuthTokenAlreadyExistsError()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AuthToken Status => Action
Not exist => Create
Exist and not expired => Error
Exist and expired => Renew

LGTM

@YoshihitoAso YoshihitoAso merged commit 20165b5 into dev-22.9 Jul 19, 2022
@YoshihitoAso YoshihitoAso deleted the feature/#354_2 branch July 19, 2022 01:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] Temporary authorization code for batch operations
2 participants