forked from Authress/authress-sdk.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
79 additions
and
14 deletions.
There are no files selected for viewing
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,28 @@ | ||
const ArgumentRequiredError = require('./argumentRequiredError'); | ||
const jwtManager = require('./jwtManager'); | ||
|
||
async function getFallbackUser(httpClient) { | ||
const token = await httpClient.tokenProvider(); | ||
const decodedJwt = jwtManager.decode(token); | ||
return decodedJwt.sub; | ||
} | ||
|
||
class ConnectionsApi { | ||
constructor(client) { | ||
this.client = client; | ||
} | ||
|
||
async getConnectionCredentials(connectionId, userId) { | ||
if (!connectionId) { | ||
throw new ArgumentRequiredError('connectionId', 'Required parameter connectionId was not specified when calling getRole.'); | ||
} | ||
|
||
const requestUserId = userId || await getFallbackUser(this.client); | ||
|
||
const url = `/v1/connections/${encodeURIComponent(String(connectionId))}/users/${encodeURIComponent(String(requestUserId))}/credentials`; | ||
const response = await this.client.get(url); | ||
return response; | ||
} | ||
} | ||
|
||
module.exports = ConnectionsApi; |