注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
1. Access Token
Imagine you want to design authentication and authorization for a branch new product at Stripe. You want your user to be able to send API requests to do things like refund payments or create new charges, but we want to reject someone who isn't authorized to send those requests. One possible solution is to mint a signed token embedded with the permission the "bearer" has.
This question will have multiple parts, but each section will all be passed to the same function. You can use the "key_mode" parameter to change the function behavior for each part. For example, if “key_mode” is equal to “permissions”, you should output from a different section of your solution than if the “key_mode” was “full_token”
Part 1: Permissions and Roles
Not every user can do the same things. You might have an admin who can do everything, a support specialist who should be able to see everything but can’t make new payments, or someone who has access to a specific product but can’t see data about any other products. We represent the things that a user is allowa binary string.
There are a total of 31 permissions, so we will generate a 31- digit binary number where each digit represents one permission. The digit will be 1 if the user has permission or 0 if they do not. The digits encode the permissions in alphabetical order, so the first digit is for capital.confirm_intent and the last digit is for payments.write_settings
Your task
Given one or more roles, return the permission binary string for that user.
Example 1
Input:
key_mode = “full_token”
roles = capital
Output:
0000011111000000000000000000000 |