🤔
パスキー認証情報を作成する
パスキー認証情報作成スクリプトの呼び出し
static/index.html
<script type="module">
import { createCredentials } from "/scripts/auth.js";
window.addEventListener("load", async () => {
createCredentials();
});
</script>
router/router.go
r.Get("/scripts/*", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
subFsys, err := fs.Sub(fsys, "static")
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(err.Error()))
return
}
http.FileServer(http.FS(subFsys)).ServeHTTP(w, r)
}))
パスキー認証情報の作成
static/scripts/auth.js
navigator.credentials.create
の引数については以下参照
export async function createCredentials() {
const credentails = await navigator.credentials.create({
publicKey: {
rp: {
name: "a10a server",
},
user: {
id: decodeBase64Url("some-user-id"),
name: "mail@a10a.app",
displayName: "mail@a10a.app",
},
challenge: decodeBase64Url("some-challenge"),
pubKeyCredParams: [
{
type: "public-key",
alg: -7,
},
{
type: "public-key",
alg: -257,
},
],
},
});
console.log({ credentails });
}
Discussion