generated from curveball/starter
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from badgateway/some-acl
When a 'client' gets created, mark the current user as 'owner'
- Loading branch information
Showing
7 changed files
with
76 additions
and
19 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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,27 @@ | ||
import ketting from './ketting'; | ||
import { LinkNotFound } from 'ketting'; | ||
|
||
|
||
|
||
export async function addUserPrivilege(principal: string|URL, privilege: string, resource: string|URL): Promise<void> { | ||
let userPrivilegesRes; | ||
|
||
try { | ||
userPrivilegesRes = await ketting.go(principal.toString()).follow('privileges'); | ||
} catch (err) { | ||
if (err instanceof LinkNotFound) { | ||
throw new Error('Link with "privileges" is not found on the user resource. This could mean that the tt-api APP in a12n-server does not have the *admin" privilege'); | ||
} | ||
throw err; | ||
} | ||
|
||
const userPrivilegesState = await userPrivilegesRes.get(); | ||
if (!userPrivilegesState.hasAction('add')) { | ||
throw new Error('The privileges resource on a12nserver does not have an \'add\' action. You likely need to update your a12n-server for this to work'); | ||
} | ||
await userPrivilegesState.action('add').submit({ | ||
action: 'add', | ||
privilege, | ||
resource: resource.toString() | ||
}); | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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,17 @@ | ||
import { Client } from 'ketting'; | ||
import oauth2Client from './oauth2'; | ||
import { OAuth2Fetch } from '@badgateway/oauth2-client'; | ||
|
||
console.debug('🔗 Setting up Ketting client'); | ||
const client = new Client(process.env.AUTH_API_URI!); | ||
|
||
const oauth2FetchWrapper = new OAuth2Fetch({ | ||
client: oauth2Client, | ||
getNewToken: () => { | ||
return oauth2Client.clientCredentials(); | ||
} | ||
}); | ||
|
||
client.use(oauth2FetchWrapper.mw()); | ||
|
||
export default client; |
This file contains 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,8 @@ | ||
import { OAuth2Client } from '@badgateway/oauth2-client'; | ||
|
||
// a12n setup | ||
export default new OAuth2Client({ | ||
server: process.env.AUTH_API_URI, | ||
clientId: process.env.OAUTH2_CLIENT_ID || 'tt-api', | ||
clientSecret: process.env.OAUTH2_CLIENT_SECRET, | ||
}); |