|
1 | 1 | # U-Bahn API |
2 | 2 |
|
3 | | -Universal Identity API |
| 3 | +## Install software |
4 | 4 |
|
5 | | -## Overview |
| 5 | +- node 12.x |
| 6 | +- npm 6.x |
| 7 | +- docker |
6 | 8 |
|
7 | | -This server was generated by the [swagger-codegen](https://github.com/swagger-api/swagger-codegen) project. By using the [OpenAPI-Spec](https://github.com/OAI/OpenAPI-Specification) from a remote server, you can easily generate a server stub. |
| 9 | +## Local deployment |
8 | 10 |
|
9 | | -### Running the server |
| 11 | +1. Visit [this link](https://console.aws.amazon.com/qldb/home?region=us-east-1#gettingStarted), login and create one **ledger** databases named `ubahn-db` |
| 12 | +2. Visit [this link](https://console.aws.amazon.com/iam/home?region=us-east-1#/security_credentials) to download your "Access keys" |
| 13 | +3. Follow *Configuration* section to update config values, like database, aws key/secret etc .. |
| 14 | +4. Goto *UBahn-api*, run `npm i` and `npm run lint` |
| 15 | +5. Import mock data, `node scripts/db/genData.js`, this will create tables and gen some data for test (if you need this) |
| 16 | +6. Startup server `node app.js` or `npm run start` |
10 | 17 |
|
11 | | -To run the server, run: |
| 18 | +## Docker |
12 | 19 |
|
13 | | -```bash |
14 | | -npm start |
15 | | -``` |
| 20 | +Make sure all config values are right(aws key and secret), and you can run on local successful, then run below commands |
16 | 21 |
|
17 | | -To view the Swagger UI interface: |
| 22 | +- Run `docker build -t tc/ubahn_api .` to build image |
| 23 | +- Then run `docker run tc/ubahn_api -d` to startup image |
18 | 24 |
|
19 | | -```bash |
20 | | -open http://localhost:8080/docs |
21 | | -``` |
| 25 | +## API endpoints verification |
22 | 26 |
|
23 | | -This project leverages the mega-awesome [swagger-tools](https://github.com/apigee-127/swagger-tools) middleware which does most all the work. |
| 27 | +1. open postman |
| 28 | +2. import *docs/UBahn_API.postman_collection.json* , *UBahn_ENV.postman_environment.json* and then check endpoints |
| 29 | + |
| 30 | +## Configuration |
| 31 | + |
| 32 | +| key | system Environment name | description | |
| 33 | +| ------------- | ----------------------- | -------------------------- | |
| 34 | +| PORT | PORT | the server port | |
| 35 | +| AUTH_SECRET | AUTH_SECRET | the jwt client secret | |
| 36 | +| VALID_ISSUERS | VALID_ISSUERS | jwt token issuers | |
| 37 | +| API_VERSION | | the api prefix version | |
| 38 | +| AWS_KEY | AWS_KEY | the aws Access key | |
| 39 | +| AWS_SECRET | AWS_SECRET | the aws Access secret | |
| 40 | +| AWS_REGION | AWS_REGION | the aws service region | |
| 41 | +| DATABASE | DATABASE | the aws QLDB database name | |
| 42 | + |
| 43 | +## Test token |
| 44 | + |
| 45 | +you can use below token to test role and permissions |
| 46 | + |
| 47 | +### 01 Topcoder User |
| 48 | + |
| 49 | +- payload |
| 50 | + |
| 51 | + ```json |
| 52 | + { |
| 53 | + "roles": [ |
| 54 | + "Topcoder User" |
| 55 | + ], |
| 56 | + "iss": "https://api.topcoder.com", |
| 57 | + "handle": "tc-user", |
| 58 | + "exp": 1685571460, |
| 59 | + "userId": "23166766", |
| 60 | + "iat": 1585570860, |
| 61 | + "email": "tc-user@gmail.com", |
| 62 | + "jti": "0f1ef1d3-2b33-4900-bb43-48f2285f9627" |
| 63 | + } |
| 64 | + ``` |
| 65 | + |
| 66 | +- token |
| 67 | + |
| 68 | + ```json |
| 69 | + eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlcyI6WyJUb3Bjb2RlciBVc2VyIl0sImlzcyI6Imh0dHBzOi8vYXBpLnRvcGNvZGVyLmNvbSIsImhhbmRsZSI6InRjLXVzZXIiLCJleHAiOjE2ODU1NzE0NjAsInVzZXJJZCI6IjIzMTY2NzY2IiwiaWF0IjoxNTg1NTcwODYwLCJlbWFpbCI6InRjLXVzZXJAZ21haWwuY29tIiwianRpIjoiMGYxZWYxZDMtMmIzMy00OTAwLWJiNDMtNDhmMjI4NWY5NjI3In0.eBhXqSBe8zMRg2nBeGeZDgKiJdAYs0zOMzGfJCjWfcs |
| 70 | + ``` |
| 71 | + |
| 72 | +#### 02 Copilot |
| 73 | + |
| 74 | +- payload |
| 75 | + |
| 76 | + ```json |
| 77 | + { |
| 78 | + "roles": [ |
| 79 | + "Topcoder User","Copilot" |
| 80 | + ], |
| 81 | + "iss": "https://api.topcoder.com", |
| 82 | + "handle": "tc-Copilot", |
| 83 | + "exp": 1685571460, |
| 84 | + "userId": "23166767", |
| 85 | + "iat": 1585570860, |
| 86 | + "email": "tc-Copilot@gmail.com", |
| 87 | + "jti": "0f1ef1d3-2b33-4900-bb43-48f2285f9628" |
| 88 | + } |
| 89 | + ``` |
| 90 | + |
| 91 | +- token |
| 92 | + |
| 93 | + ```json |
| 94 | + eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlcyI6WyJUb3Bjb2RlciBVc2VyIiwiQ29waWxvdCJdLCJpc3MiOiJodHRwczovL2FwaS50b3Bjb2Rlci5jb20iLCJoYW5kbGUiOiJ0Yy1Db3BpbG90IiwiZXhwIjoxNjg1NTcxNDYwLCJ1c2VySWQiOiIyMzE2Njc2NyIsImlhdCI6MTU4NTU3MDg2MCwiZW1haWwiOiJ0Yy1Db3BpbG90QGdtYWlsLmNvbSIsImp0aSI6IjBmMWVmMWQzLTJiMzMtNDkwMC1iYjQzLTQ4ZjIyODVmOTYyOCJ9.gP5JqJGCnOjO_gYs2r3-AQt5x8YIym15m3t43603cgc |
| 95 | + ``` |
| 96 | + |
| 97 | +#### 03 Admin |
| 98 | + |
| 99 | +- payload |
| 100 | + |
| 101 | + ```json |
| 102 | + { |
| 103 | + "roles": [ |
| 104 | + "Topcoder User","Copilot","Admin" |
| 105 | + ], |
| 106 | + "iss": "https://api.topcoder.com", |
| 107 | + "handle": "tc-Admin", |
| 108 | + "exp": 1685571460, |
| 109 | + "userId": "23166768", |
| 110 | + "iat": 1585570860, |
| 111 | + "email": "tc-Admin@gmail.com", |
| 112 | + "jti": "0f1ef1d3-2b33-4900-bb43-48f2285f9630" |
| 113 | + } |
| 114 | + ``` |
| 115 | + |
| 116 | +- token |
| 117 | + |
| 118 | + ```json |
| 119 | + eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlcyI6WyJUb3Bjb2RlciBVc2VyIiwiQ29waWxvdCIsIkFkbWluIl0sImlzcyI6Imh0dHBzOi8vYXBpLnRvcGNvZGVyLmNvbSIsImhhbmRsZSI6InRjLUFkbWluIiwiZXhwIjoxNjg1NTcxNDYwLCJ1c2VySWQiOiIyMzE2Njc2OCIsImlhdCI6MTU4NTU3MDg2MCwiZW1haWwiOiJ0Yy1BZG1pbkBnbWFpbC5jb20iLCJqdGkiOiIwZjFlZjFkMy0yYjMzLTQ5MDAtYmI0My00OGYyMjg1Zjk2MzAifQ.eR97kePT0Gu-t7vUE0Ed8A88Dnmtgebyml2jrRyxhOk |
| 120 | + ``` |
| 121 | + |
| 122 | +#### M2M token 01 |
| 123 | + |
| 124 | +- payload, this token missing `all:usersSkill`, so all endpoints in usersSkill group will return 403 |
| 125 | + |
| 126 | + ```json |
| 127 | + { |
| 128 | + "scopes": "all:user all:role all:skill all:usersRole all:organization all:skillsProvider", |
| 129 | + "iss": "https://api.topcoder.com", |
| 130 | + "handle":"tc-mm-01", |
| 131 | + "exp": 1685571460, |
| 132 | + "iat": 1585570860, |
| 133 | + "jti": "0f1ef1d3-2b33-4900-bb43-48f2285f9630" |
| 134 | + } |
| 135 | + ``` |
| 136 | + |
| 137 | +- token |
| 138 | + |
| 139 | + ```json |
| 140 | + eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzY29wZXMiOiJhbGw6dXNlciBhbGw6cm9sZSBhbGw6c2tpbGwgYWxsOnVzZXJzUm9sZSBhbGw6b3JnYW5pemF0aW9uIGFsbDpza2lsbHNQcm92aWRlciIsImlzcyI6Imh0dHBzOi8vYXBpLnRvcGNvZGVyLmNvbSIsImhhbmRsZSI6InRjLW1tLTAxIiwiZXhwIjoxNjg1NTcxNDYwLCJpYXQiOjE1ODU1NzA4NjAsImp0aSI6IjBmMWVmMWQzLTJiMzMtNDkwMC1iYjQzLTQ4ZjIyODVmOTYzMCJ9.BlDIYsCTcHTib9XhpyzpO-KkMTTMy0egq_7qlLWRmoM |
| 141 | + ``` |
| 142 | + |
| 143 | +#### M2M token 02 |
| 144 | + |
| 145 | +- payload, this token contains scope, can request all endpoints |
| 146 | + |
| 147 | + ```json |
| 148 | + { |
| 149 | + "scopes": "all:user all:role all:skill all:usersRole all:organization all:skillsProvider all:usersSkill all:externalProfile all:achievementsProvider all:achievement all:attributeGroup all:attribute all:userAttribute", |
| 150 | + "iss": "https://api.topcoder.com", |
| 151 | + "handle": "tc-mm-02", |
| 152 | + "exp": 1685571460, |
| 153 | + "iat": 1585570860, |
| 154 | + "jti": "0f1ef1d3-2b33-4900-bb43-48f2285f9630" |
| 155 | + } |
| 156 | + ``` |
| 157 | + |
| 158 | +- token |
| 159 | + |
| 160 | + ```json |
| 161 | + eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzY29wZXMiOiJhbGw6dXNlciBhbGw6cm9sZSBhbGw6c2tpbGwgYWxsOnVzZXJzUm9sZSBhbGw6b3JnYW5pemF0aW9uIGFsbDpza2lsbHNQcm92aWRlciBhbGw6dXNlcnNTa2lsbCBhbGw6ZXh0ZXJuYWxQcm9maWxlIGFsbDphY2hpZXZlbWVudHNQcm92aWRlciBhbGw6YWNoaWV2ZW1lbnQgYWxsOmF0dHJpYnV0ZUdyb3VwIGFsbDphdHRyaWJ1dGUgYWxsOnVzZXJBdHRyaWJ1dGUiLCJpc3MiOiJodHRwczovL2FwaS50b3Bjb2Rlci5jb20iLCJoYW5kbGUiOiJ0Yy1tbS0wMiIsImV4cCI6MTY4NTU3MTQ2MCwiaWF0IjoxNTg1NTcwODYwLCJqdGkiOiIwZjFlZjFkMy0yYjMzLTQ5MDAtYmI0My00OGYyMjg1Zjk2MzAifQ.8XJahLdv9mkgkL7EsOwsf8uKg4J9u-1UM73pvZ9n3JY |
| 162 | + ``` |
0 commit comments