Last active
February 26, 2020 21:31
-
-
Save thomsbg/8b35e185967e8b03c248113f8ce10ed5 to your computer and use it in GitHub Desktop.
ApiClient plain class
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
class ApiClient { | |
constructor(jwt) { | |
// parse + verify jwt | |
// set properties based on jwt claims | |
} | |
user() { | |
if (this.user_id) { | |
return towerRequest(USER_INFO, { user_id: this.user_id }); | |
} else { | |
return null; | |
} | |
} | |
rolesFor(context) { | |
// filter roles in jwt to those that apply to a given context | |
// (organization, network, community, etc) | |
} | |
permittedTo(operation, context) { | |
return this.rolesFor(context).some(role => { | |
roleConfig[role].operations.include(operation); | |
}); | |
} | |
} |
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
{ | |
"aud": "https://api.{org}.usechorus.com", | |
"iss": "https://login.usechorus.com", | |
"full_name": "Blake Thomson", | |
"https://usechorus.com/user_id": 12345, | |
"https://usechorus.com/roles": { | |
"global": [ | |
"role_a", | |
"role_b", | |
], | |
"network:123": [ | |
"role_f" | |
], | |
"community:456": [ | |
"role_c", | |
"role_d" | |
], | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment