auth.signin(params, function(profile, token) { //Set user as admin if they did not use a social login. profile.isAdmin = !profile.identities[0].isSocial; store.set('profile', profile); store.set('token', token); // get delegation token from identity token. var options = getOptionsForRole(profile.isAdmin, token); // TODO: Step 3: Enable this section once you setup AWS delegation. /* auth.getToken(options) .then( function(delegation) { store.set('awstoken', delegation.Credentials); $location.path("/"); }, function(err) { console.log('failed to acquire delegation token', err); }); */ // TODO: Step 3: Remove this redirect after you add the get token API. $location.path("/");}, function(error) { console.log("There was an error logging in", error);});
ダウンロードを確認するには、AWS API Gatewayチュートリアルの手順2を参照してください。petsディレクトリにはすでにREADME.mdがあるため、ディレクトリ内の両方のファイルを維持するために、ファイルの1つの名前を変更する必要があります。APIゲートウェイのREADME.mdは、Auth0アプリケーションのAPIアプリケーションの使用方法について説明しています。petsフォルダーのルートにあるindex.htmlファイルを開き、API readmeの上部にリスト表示されているスクリプトすべてをindex.htmlに追加します。
Copy
Ask AI
<!-- scripts for aws api gateway include after you create your package from aws for api gateway. --><script type="text/javascript" src="/lib/axios/dist/axios.standalone.js"></script><script type="text/javascript" src="/lib/CryptoJS/rollups/hmac-sha256.js"></script><script type="text/javascript" src="/lib/CryptoJS/rollups/sha256.js"></script><script type="text/javascript" src="/lib/CryptoJS/components/hmac.js"></script><script type="text/javascript" src="/lib/CryptoJS/components/enc-base64.js"></script><script type="text/javascript" src="/lib/moment/moment.js"></script><script type="text/javascript" src="/lib/url-template/url-template.js"></script><script type="text/javascript" src="/lib/apiGatewayCore/sigV4Client.js"></script><script type="text/javascript" src="/lib/apiGatewayCore/apiGatewayClient.js"></script><script type="text/javascript" src="/lib/apiGatewayCore/simpleHttpClient.js"></script><script type="text/javascript" src="/lib/apiGatewayCore/utils.js"></script><script type="text/javascript" src="/apigClient.js"></script>
function getPets() { // this is unauthenticated var apigClient = apigClientFactory.newClient({ region: 'us-east-1' // The region where the API is deployed }); apigClient.petsGet({},{}) .then(function(response) { console.log(response); $scope.pets = response.data; $scope.$apply(); }).catch(function (response) { alert('pets get failed'); showError(response); });}
function putPets(updatedPets) { var body = {pets: updatedPets}; var apigClient = apigClientFactory.newClient({ region: 'us-east-1' // set this to the region you are running in. }); apigClient.petsPost({},body) .then(function(response) { console.log(response); }).catch(function (response) { alert('pets update failed'); showError(response); });}
更新済みのコードを、S3バケットにコピーします。メソッドをテストします。
ログアウトし、ログインし直します
Pet TypeおよびPet Priceの値に入力します。
[Save(保存)] をクリックしてデータをポストします。
「We have a <Pet Type> for sale for <Pet Price>(<Pet Price>で販売されている<Pet Type>がいます)」のメッセージと、左側に赤色の [REMOVE(削除)] ボタンが表示されます。セキュリティを追加するために、putPetsメソッドの始めにgetSecureApiClient関数を追加します。
Copy
Ask AI
function putPets(updatedPets) { var apigClient = getSecureApiClient();}
function getSecureApiClient() { var awstoken = store.get('awstoken'); return apigClientFactory.newClient({ accessKey: awstoken.AccessKeyId, secretKey: awstoken.SecretAccessKey, sessionToken: awstoken.SessionToken, region: 'us-east-1' // The region you are working out of. }); }