Created
September 10, 2019 16:45
-
-
Save gpDA/f8a5893e5f9009c8323a212a3a3af535 to your computer and use it in GitHub Desktop.
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
| import { Auth } from 'aws-amplify'; | |
| import * as aws4 from 'aws4'; | |
| // get Function | |
| export const get = async (path, use_access_token, options = null) => { | |
| let user = await Auth.currentAuthenticatedUser(); | |
| let idToken = user.signInUserSession.idToken.jwtToken; | |
| let accessToken = user.signInUserSession.accessToken.jwtToken; | |
| const apiName = "XXXX" | |
| const signer = aws4.sign({ | |
| service: 'execute-api', | |
| region: 'us-east-1', | |
| hostname: 'https://XXXX.us-east-1.amazonaws.com/' + version, | |
| path: path, | |
| headers: { | |
| 'Content-Type': 'application/json', | |
| 'Token': idToken, | |
| 'Accept': 'application/json' | |
| } | |
| }, { | |
| accessKeyId: 'XXXX', | |
| secretAccessKey: 'XXXXX', | |
| sessionToken: null | |
| }); | |
| const ops = { | |
| headers: { | |
| Token: header_token, | |
| Authorization: 'Authorization:' + signer.headers.Authorization | |
| } | |
| } | |
| return API.get(apiName, path, ops) | |
| } | |
| // Get request in ACTION | |
| export const checkApi = () => get('/XXX', true) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment