-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AWSの勉強 #7
Comments
過去にAWSアカウントを停止してしまっていた。 |
付録Bのインストールとセットアップをやる。 |
aws-cliをインストールする。
|
IAM (Identity and Access Management) を設定する。 |
最初のlambdaを作成し、ローカルでテストする。
|
なんか文句を言われたので、言われた通りやってみる。
|
ムムム?
にaws-sdkがない。
OK! |
package.jsonのscriptsにdeployとpredeployを追加する。
OK! |
AWS Lambdaで動作確認する。 できたぁ! |
あ、serverless-video-transcoded-nkbじゃなくて、severlessになっている…。ひどいtypoだ…。 |
https://www.johnvansickle.com/ffmpeg/ ffmpegのスタティックビルドを使う。 |
26M 7月 10 20:34 Lambda-Deployment.zip 26MBか。ffprobeが61MBなのにけっこう小さくなるもんだ。 |
3章が一通り終わった。けっこうGUIでポチポチしないといけないのが面倒だが、簡単にできるな。 |
演習問題は一旦お預けで、前に進もう。 |
4章はセキュリティ、ログ、アラート、課金、全て重要だな! |
pp.86 ポリシーのバージョンに2018が含まれているとダメらしい?なんで? かならず、2012-10-17を指定しないといけないらしい。あっそ。 |
仮想マシンを切ってしまった…。明日デプロイテストをしよう。 |
第2部第5章
このあたりのことがわかるようだ。 |
Amazon Cognitoも知りたかったが、これは範囲外か…。 |
少し付録Cに寄り道。認証と認可について。 |
うーん、ちょっと認証周りの説明がちゃんと理解できていないな。作ってから一旦戻ってくる必要がありそうだ。 |
webサイトをホスティングするのに、local-web-serverモジュールが利用できる。
"scripts": {
"start": "ws",
"test": "echo \"Error: no test specified\" && exit 1"
}, package.jsonに↑のように書いて、npm startでweb serverが起動する。あとはブラウザでアクセスすればよい。 |
html5のローカルストレージ機能を使っている。 var idToken = localStorage.getItem('userToken');
if (idToken) {
this.configureAuthenticatedRequests();
this.data.auth0Lock.getProfile(idToken, function(err, profile) {
if (err) {
return alert('There was an error getting the profile: ' + err.message);
}
that.showUserAuthenticationDetails(profile);
});
} |
今後、HTTPリクエストを出すときに、HTTPリクエストのAuthorizationヘッダーにtokenが組み込まれる、と。 configureAuthenticatedRequests: function() {
$.ajaxSetup({
'beforeSend': function(xhr) {
xhr.setRequestHeader('Authorization', 'Bearer ' + localStorage.getItem('userToken'));
}
});
}, |
sign upもlog inもできないが?と思ったら、auth0にアカウントは作られている? |
うーん?パスワード変更とかはできるぞ。ページからうまくリクエストを遅れていない? |
やっとできた…。 auth0の設定でAllowed Web Originsを設定しないとダメみたい。しょーもな…。 |
ログアウトボタンにトグルしないんだよなぁ。気になるが、少し先に進めるか。 |
Auth0のAPIバージョンの9が使えなくなっているのか…。 |
https://auth0.com/docs/libraries/lock/v11 ここを参考に作り替えよう。 <script src="https://cdn.auth0.com/js/lock/11.6.1/lock.min.js"></script>
<script>
var lock = new Auth0Lock('XT8qlbyX4sKkJpjb8QMvprEZmuQ345T5', 't-nakabayashi.auth0.com', {
auth: {
redirectUrl: 'http://127.0.0.1:8000',
responseType: 'code',
params: {
scope: 'openid email' // Learn about scopes: https://auth0.com/docs/scopes
}
}
});
</script>
<button onclick="lock.show();">Login</button> |
This comment has been minimized.
This comment has been minimized.
変更箇所 newするときにパラメータを指定しろ、とのことなので、APIリファレンス通りに設定する。 this.data.auth0Lock = new Auth0Lock(config.auth0.clientId, config.auth0.domain, {
auth: {
redirectUrl: 'http://127.0.0.1:8000',
responseType: 'code',
params: {
scope: 'openid email user_metadata picture' // Learn about scopes: https://auth0.com/docs/scopes
}
}
}); ユーザー情報を取得するAPIが、getProfile()からgetUserInfo()に変更されている。 if (idToken) {
this.configureAuthenticatedRequests();
this.data.auth0Lock.getUserInfo(idToken, function(err, profile) { show()でエラーハンドリングするのではなく、on()でイベントを処理するAPI仕様になっている。 this.data.auth0Lock.on("authenticated", function(authResult) {
that.data.auth0Lock.getUserInfo(authResult.accessToken, function(error, profile) {
that.data.auth0Lock.hide();
if (error) return alert("Auth0 error:" + error);
localStorage.setItem("userToken", authResult.accessToken);
that.configureAuthenticatedRequests();
that.showUserAuthenticationDetails(profile);
})
});
this.uiElements.loginButton.click(function(e) {
that.data.auth0Lock.show({
auth: {
params: {
responseType: 'id_token token'
}
}
});
}); |
curlだと返ってくるね。lambdaでこれが返せればいいわけだ。
|
やっと進んだ。長かった。 $.getの返り値がよくわからん。あとで調べておこう。 |
結局、↓で言っている通りで、トークンを両方送らないとダメなんでしょう。問題はどうやって両方送るか、なんだが。
|
$なんとかってjQueryの関数なのか。 $.get()は次のような感じなので、data部分にidTokenを埋め込んであげれば良い? http://semooh.jp/jquery/api/ajax/jQuery.get/+url,+data,+callback+/ ちゃんと見ると↓に書いてありそう。bodyで渡すならpostだよなぁ。クエリパラメータで渡すか? |
付録EにAPI Gatewayのマッピングについて書いてある。GETメソッドのクエリパラメータで追加してみよう。 |
カスタムリクエストヘッダー、そういうのもあるのか |
https://auth0.com/docs/integrations/aws/tokens delegationか。POSTのbodyでid_tokenを投げているな。access tokenは? |
AWSによるサーバレスアーキテクチャをやる。
ソースコードはここ。
https://github.com/sbarski/serverless-architectures-aws
The text was updated successfully, but these errors were encountered: