{"id":392,"date":"2019-05-28T10:11:53","date_gmt":"2019-05-28T01:11:53","guid":{"rendered":"http:\/\/localhost:8000\/?p=392"},"modified":"2021-01-23T12:14:57","modified_gmt":"2021-01-23T03:14:57","slug":"ktor-google-authentication","status":"publish","type":"post","link":"http:\/\/localhost:8000\/2019\/05\/ktor-google-authentication.html","title":{"rendered":"Ktor\u3067\u69cb\u7bc9\u3057\u305fAPI\u30b5\u30fc\u30d0\u306eGoogle OAuth\u8a8d\u8a3c\u51e6\u7406\u306e\u5168\u4f53\u50cf"},"content":{"rendered":"
\u6700\u521d\u306f\u3001Ktor\u3067API\u30b5\u30fc\u30d0\u3092\u4f5c\u308b\u306b\u3042\u305f\u308a\u3001\u516c\u5f0f\u30da\u30fc\u30b8<\/a> \u3092\u53c2\u8003\u306b\u30d0\u30c3\u30af\u30a8\u30f3\u30c9\u3067Google OAuth\u8a8d\u8a3c\u3092\u884c\u3046\u5b9f\u88c5\u3092\u884c\u306a\u3063\u305f\u3002 \u30ea\u30d0\u30fc\u30b9\u30d7\u30ed\u30ad\u30b7\u3067\u30d5\u30ed\u30f3\u30c8\u30a8\u30f3\u30c9\u3068\u30d0\u30c3\u30af\u30a8\u30f3\u30c9\u306e\u30c9\u30e1\u30a4\u30f3\u3092\u7d71\u4e00\u3057\u3066\u307f\u3066\u3082\u3046\u307e\u304f\u89e3\u6c7a\u3067\u304d\u305a\u3001\u7d50\u5c40\u516c\u5f0f\u3067\u7d39\u4ecb\u3055\u308c\u3066\u3044\u308bGoogle OAuth\u8a8d\u8a3c\u306f\u8ae6\u3081\u3001\u81ea\u524d\u3067\u8a8d\u8a3c\u51e6\u7406\u3092\u5b9f\u88c5\u3059\u308b\u3053\u3068\u306b\u3057\u305f\u3002<\/strong><\/p>\n <\/p>\n vue-google-oauth2\u306e\u4f9d\u5b58\u95a2\u4fc2\u3092\u8ffd\u52a0\u3059\u308b\u3002<\/p>\n \u51e6\u7406\u306e\u6d41\u308c\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3002<\/p>\n \u51e6\u7406\u306e\u6d41\u308c\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3002<\/p>\n \u307e\u305a\u306fGoogle APIs\u306eclient\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u4f9d\u5b58\u95a2\u4fc2\u3092\u8ffd\u52a0\u3059\u308b\u3002<\/p>\n \u57fa\u672c\u7684\u306b\u306f\u4ee5\u4e0b\u306e\u6d41\u308c\u3067\u5404URL\u304c\u547c\u3073\u51fa\u3055\u308c\u308b\u3053\u3068\u3092\u60f3\u5b9a\u3057\u3066\u3044\u308b\u3002<\/p>\n \u3084\u308b\u3068\u6c7a\u3081\u3066\u304b\u3089\u306e\u5b9f\u88c5\u81ea\u4f53\u306f\u7d50\u69cb\u65e9\u304f\u3067\u304d\u305f\u304c\u3001\u3069\u3046\u306b\u304b\u516c\u5f0f\u306e\u65b9\u6cd5\u3067\u3046\u307e\u304f\u3084\u308c\u306a\u3044\u304b\u3092\u8abf\u3079\u308b\u306e\u306f\u3081\u3061\u3083\u304f\u3061\u3083\u6642\u9593\u304c\u304b\u304b\u3063\u305f\u3002\u307e\u3060\u5229\u7528\u8005\u304c\u5c11\u306a\u3044\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u306e\u6b20\u70b9\u3060\u3068\u601d\u3046\u3002\u3042\u3068\u3001\u81ea\u524d\u5b9f\u88c5\u306b\u3057\u305f\u7d50\u679c\u3001\u30d6\u30e9\u30c3\u30af\u30dc\u30c3\u30af\u30b9\u611f\u304c\u4e00\u5207\u306a\u304f\u306a\u308a\u5168\u3066\u5236\u5fa1\u53ef\u80fd\u306b\u306a\u3063\u305f\u3053\u3068\u306f\u5927\u304d\u306a\u30e1\u30ea\u30c3\u30c8\u3060\u3068\u601d\u3046\u3002<\/p>\n","protected":false},"excerpt":{"rendered":" \u6700\u521d\u306f\u3001Ktor\u3067API\u30b5\u30fc\u30d0\u3092\u4f5c\u308b\u306b\u3042\u305f\u308a\u3001\u516c\u5f0f\u30da\u30fc\u30b8 \u3092\u53c2\u8003\u306b\u30d0\u30c3\u30af\u30a8\u30f3\u30c9\u3067Google OAuth\u8a8d\u8a3c\u3092\u884c\u3046\u5b9f\u88c5\u3092\u884c\u306a\u3063\u305f\u3002 \u3057\u304b\u3057\u3001\u30d5\u30ed\u30f3\u30c8\u30a8\u30f3\u30c9\u304b\u3089API\u3092\u547c\u3073\u51fa\u3057\u305f\u969b\u306b\u3001 \u30d5\u30ed\u30f3\u30c8\u30a8\u30f3\u30c9 => \u30d0\u30c3\u30af\u30a8\u30f3\u30c9 => (redirect) => account.google.com \u306e\u69d8\u306a\u6d41\u308c\u3067\u3001CORS\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3059\u308b\u3053\u3068\u304c\u5206\u304b\u3063\u305f\uff08\u8a73\u7d30\u306f\u3053\u3061\u3089\uff09\u3002 \u30ea\u30d0\u30fc\u30b9\u30d7\u30ed\u30ad\u30b7\u3067\u30d5\u30ed\u30f3\u30c8\u30a8\u30f3\u30c9\u3068\u30d0\u30c3\u30af\u30a8\u30f3\u30c9\u306e\u30c9\u30e1\u30a4\u30f3\u3092\u7d71\u4e00\u3057\u3066\u307f\u3066\u3082\u3046\u307e\u304f\u89e3\u6c7a\u3067\u304d\u305a\u3001\u7d50\u5c40\u516c\u5f0f\u3067\u7d39\u4ecb\u3055\u308c\u3066\u3044\u308bGoogle OAuth\u8a8d\u8a3c\u306f\u8ae6\u3081\u3001\u81ea\u524d\u3067\u8a8d\u8a3c\u51e6\u7406\u3092\u5b9f\u88c5\u3059\u308b\u3053\u3068\u306b\u3057\u305f\u3002 \u51e6\u7406\u306e\u6d41\u308c \u30d5\u30ed\u30f3\u30c8\u30a8\u30f3\u30c9\u5074\u306e\u5b9f\u88c5 package.json vue-google-oauth2\u306e\u4f9d\u5b58\u95a2\u4fc2\u3092\u8ffd\u52a0\u3059\u308b\u3002 "dependencies": { "vue-google-oauth2&quo <\/span>Continue Reading<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[27,28],"tags":[],"_links":{"self":[{"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/posts\/392"}],"collection":[{"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/comments?post=392"}],"version-history":[{"count":1,"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/posts\/392\/revisions"}],"predecessor-version":[{"id":394,"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/posts\/392\/revisions\/394"}],"wp:attachment":[{"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/media?parent=392"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/categories?post=392"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/tags?post=392"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}
\n\u3057\u304b\u3057\u3001\u30d5\u30ed\u30f3\u30c8\u30a8\u30f3\u30c9\u304b\u3089API\u3092\u547c\u3073\u51fa\u3057\u305f\u969b\u306b\u3001
\n\u30d5\u30ed\u30f3\u30c8\u30a8\u30f3\u30c9 => \u30d0\u30c3\u30af\u30a8\u30f3\u30c9 => (redirect) => account.google.com
\n\u306e\u69d8\u306a\u6d41\u308c\u3067\u3001CORS\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3059\u308b\u3053\u3068\u304c\u5206\u304b\u3063\u305f\uff08\u8a73\u7d30\u306f\u3053\u3061\u3089<\/a>\uff09\u3002<\/p>\n\u51e6\u7406\u306e\u6d41\u308c<\/h2>\n
\u30d5\u30ed\u30f3\u30c8\u30a8\u30f3\u30c9\u5074\u306e\u5b9f\u88c5<\/h2>\n
package.json<\/h3>\n
"dependencies": {\n "vue-google-oauth2": "^1.3.8"\n }<\/code><\/pre>\n
App.vue<\/h3>\n
\n
created<\/code>\u306b\u3066\u3001Google OAuth\u8a8d\u8a3c\u6a5f\u80fd\u306e\u521d\u671f\u5316\u3092\u884c\u306a\u3046\u3002<\/li>\n
loggedIn = false<\/code>\u3092\u8a2d\u5b9a\u3059\u308b\u3002<\/li>\n
loggedIn = false<\/code>\u306a\u306e\u3067\u3001
Hoge<\/code>\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306f\u975e\u8868\u793a\u306b\u306a\u308a\u3001
Login<\/code>\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u304c\u8868\u793a\u3055\u308c\u308b\u3002<\/li>\n
succeeded<\/code>\u3068\u3044\u3046\u30a4\u30d9\u30f3\u30c8\u306b\u5bfe\u3057\u3066
loginSucceeded<\/code>\u3092\u7d10\u3065\u3051\u308b\u3002Login\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u5074\u3067\u8a8d\u8a3c\u304c\u5b8c\u4e86\u3057\u305f\u3089
succeeded<\/code>\u3092Emit\u3059\u308b\u3002<\/li>\n
scceeded<\/code>\u30a4\u30d9\u30f3\u30c8\u304cEmit\u3055\u308c\u305f\u3089\u3001
loginSucceeded<\/code>\u30e1\u30bd\u30c3\u30c9\u304ccall\u3055\u308c\u3001
loggedIn = true<\/code>\u304c\u8a2d\u5b9a\u3055\u308c\u308b\u3002<\/li>\n
loggedIn = true<\/code>\u306b\u306a\u3063\u305f\u306e\u3067\u3001
Login<\/code>\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306f\u975e\u8868\u793a\u306b\u306a\u308a\u3001
Hoge<\/code>\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u304c\u8868\u793a\u3055\u308c\u308b\u3002<\/li>\n<\/ol>\n
<template>\n <div id="app">\n <div v-if=loggedIn>\n <Hoge :url=url \/>\n <\/div>\n <div v-else>\n <Login @succeeded=loginSucceeded \/>\n <\/div>\n <\/div>\n<\/template>\n:\nimport GAuth from 'vue-google-oauth2'\n:\nexport default class App extends Vue {\n private loggedIn: boolean = false\n\n created (): void {\n const GOOGLE_OAUTH_OPTION = {\n clientId: '**********.apps.googleusercontent.com',\n scope: 'profile email',\n prompt: 'select_account'\n }\n Vue.use(GAuth, GOOGLE_OAUTH_OPTION)\n }\n\n @Emit()\n loginSucceeded (): void {\n this.loggedIn = true\n }\n}<\/code><\/pre>\n
Login.vue<\/h3>\n
\n
@Emit<\/code>\u306b\u3088\u3063\u3066\u3001
succeeded<\/code>\u30a4\u30d9\u30f3\u30c8\u304c\u5b9a\u7fa9\u3055\u308c\u308b<\/li>\n
loginChecked = false<\/code>\u304c\u8a2d\u5b9a\u3055\u308c\u308b\u3002<\/li>\n
mounted<\/code>\u306b\u3066\u30d0\u30c3\u30af\u30a8\u30f3\u30c9\u30b5\u30fc\u30d0\u306b\u8a8d\u8a3c\u6e08\u307f\u304b\u3069\u3046\u304b\u3092ajax\u3067\u554f\u3044\u5408\u308f\u305b\u308b\u3002\n
\n
200<\/code>\u3092\u672a\u8a8d\u8a3c\u306a\u3089\u3070
401<\/code>\u304c\u8fd4\u3059\u3002<\/li>\n<\/ul>\n<\/li>\n
401<\/code>\u304c\u8fd4\u3063\u3066\u304d\u305f\u3089\u3001
loginChecked = true<\/code>\u3092\u8a2d\u5b9a\u3059\u308b\u3002<\/li>\n
loginChecked = true<\/code>\u304c\u8a2d\u5b9a\u3055\u308c\u305f\u306e\u3067\u3001
authenticate<\/code>\u30dc\u30bf\u30f3\u304c\u8868\u793a\u3055\u308c\u308b\u3002<\/li>\n
authenticate<\/code>\u30dc\u30bf\u30f3\u3092\u30af\u30ea\u30c3\u30af\u3059\u308b\u3068\u3001Google OAuth\u8a8d\u8a3c\u30ea\u30af\u30a8\u30b9\u30c8\u304caccount.google.com\u3078\u9001\u4fe1\u3055\u308c\u308b\u3002<\/li>\n
idToken<\/code>\u3092\u53d6\u5f97\u3059\u308b\u3002<\/li>\n
idToken<\/code>\u3092\u5143\u306b\u3001\u30a2\u30d7\u30ea\u306e\u30ed\u30b0\u30a4\u30f3\u51e6\u7406\u3092\u547c\u3073\u51fa\u3059\u3002<\/li>\n
succeeded<\/code>\u30a4\u30d9\u30f3\u30c8\u3092emit\u3059\u308b\u3002<\/li>\n<\/ol>\n
<template>\n <div v-if=loginChecked>\n \u672c\u6a5f\u80fd\u3092\u5229\u7528\u3059\u308b\u305f\u3081\u306b\u306f\u3001Google\u8a8d\u8a3c\u304c\u5fc5\u8981\u3067\u3059\u3002<br\/>\n <button @click="handleAuthenticateButton">authenticate<\/button>\n <\/div>\n<\/template>\n\n<script lang="ts">\nimport { Component, Prop, Vue, Emit } from 'vue-property-decorator'\nimport axios from 'axios'\n\n@Component\nexport default class Login extends Vue {\n @Emit() private succeeded () {}\n\n private loginChecked: boolean = false\n\n mounted (): void {\n axios\n .get('http:\/\/rinoguchi.io\/logged_in')\n .then(response => {\n this.succeeded()\n })\n .finally(() => {\n this.loginChecked = true\n })\n }\n\n handleAuthenticateButton () {\n const gAuth = this.$root.$gAuth\n gAuth.signIn()\n .then(GoogleUser => {\n const idToken = GoogleUser.getAuthResponse().id_token\n this.loginApplication(idToken)\n })\n .catch(error => {\n alert('\u30dd\u30c3\u30d7\u30a2\u30c3\u30d7\u304c\u30d6\u30ed\u30c3\u30af\u3055\u308c\u3066\u3044\u308b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002\u30dd\u30c3\u30d7\u30a2\u30c3\u30d7\u3092\u8a31\u53ef\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002')\n console.log(error)\n })\n }\n\n loginApplication (idToken: string) {\n axios\n .get('http:\/\/rinoguchi.io\/login', { params: { 'id_token': idToken } })\n .then(response => {\n this.succeeded() \/\/ \u89aa\u306e`succeeded`\u30a4\u30d9\u30f3\u30c8\u3092emit\n })\n .catch(error => {\n alert(' Login error occurred. detail: ' + error)\n })\n }\n}\n<\/script><\/code><\/pre>\n
\u30d0\u30c3\u30af\u30a8\u30f3\u30c9\u5074\u306e\u5b9f\u88c5<\/h2>\n
build.gradle<\/h3>\n
dependencies {\n compile "com.google.api-client:google-api-client:1.28.0"\n}<\/code><\/pre>\n
MainApp.kt<\/h3>\n
\n
\n
secretSignKey<\/code>\u306f\u74b0\u5883\u5909\u6570\u3092application.conf\u3067\u8aad\u307f\u8fbc\u3093\u3067\u3001\u305d\u308c\u3092\u4f7f\u3046\u3088\u3046\u306b\u3057\u3066\u3042\u308b\u3002<\/li>\n
HOGE_SESSION_ID<\/code>\u3068\u3044\u3046\u540d\u524d\u306e\u30af\u30c3\u30ad\u30fc\u304c\u751f\u6210\u3055\u308c\u308b\u3088\u3046\u306b\u306a\u308b\u3002<\/li>\n<\/ul>\n<\/li>\n
\n
session-auth<\/code>\u3092\u3064\u3051\u3066\u3042\u308b\u3002Rooting\u5074\u3067\u8a8d\u8a3c\u7bc4\u56f2\u3092\u6307\u5b9a\u3059\u308b\u969b\u306b\u3053\u306e\u540d\u79f0\u3092\u5229\u7528\u3059\u308b\u3002<\/li>\n
validate<\/code>\u30e1\u30bd\u30c3\u30c9\u306b\u6e21\u3057\u3066\u3044\u308b\u30d6\u30ed\u30c3\u30af\u306e\u4e2d\u8eab\u304c\u8a8d\u8a3c\u51e6\u7406\u306e\u672c\u4f53\u3002<\/li>\n
Principal<\/code>\u3092\u8fd4\u3057\u3001\u4e0d\u6210\u529f\u306e\u5834\u5408\u306f
null<\/code>\u3092\u8fd4\u3059\u5fc5\u8981\u304c\u3042\u308b\u3002<\/li>\n
Principal<\/code>\u3092\u3001\u3067\u304d\u306a\u3051\u308c\u3070
null<\/code>\u3092\u8fd4\u3059\u69d8\u306b\u3057\u3066\u3042\u308b<\/li>\n
challenge<\/code>\u306b\u6e21\u3057\u3066\u3044\u308b\u5185\u5bb9\u306f\u3001\u8a8d\u8a3c\u5931\u6557\u306e\u6642\u306e\u6319\u52d5\u3092\u6307\u5b9a\u3059\u308b\u3082\u306e\u3002<\/li>\n
SessionAuthChallenge.Unauthorized<\/code>\u3092\u6307\u5b9a\u3059\u308c\u3070\u3001
401 Unauthorized<\/code>\u304c\u8fd4\u308b\u3002\u4eca\u56de\u306f\u3053\u308c\u3092\u5229\u7528\u3057\u3066\u3044\u308b\u3002<\/li>\n
SessionAuthChallenge.Redirect<\/code>\u3092\u6307\u5b9a\u3059\u308c\u3070\u3001\u7279\u5b9a\u306eurl\u306b\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u3059\u308b\u3053\u3068\u3067\u304d\u308b<\/li>\n
SessionAuthChallenge.Ignore<\/code>\u3092\u6307\u5b9a\u3059\u308c\u3070\u3001\u4f55\u4e8b\u3082\u306a\u304f\u8a8d\u8a3c\u51e6\u7406\u3092\u7d42\u3048\u3066\u3001\u5f8c\u7d9a\u51e6\u7406\u3092\u547c\u3073\u51fa\u3059\u3053\u3068\u3082\u3067\u304d\u308b<\/li>\n
skipWhen<\/code>\u3082\u5229\u7528\u3059\u308b\u30b1\u30fc\u30b9\u306f\u3042\u308b\u3068\u601d\u3046\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n
data class SessionAccount(val googleId: String, val googleName: String) \n\nfun Application.module() {\n \/\/ \u30bb\u30c3\u30b7\u30e7\u30f3\n install(Sessions) {\n cookie<SessionAccount>("HOGE_SESSION_ID") {\n val secretSignKey = hex(environment.config.property("app.session.secret_key").getString())\n transform(SessionTransportTransformerMessageAuthentication(secretSignKey))\n }\n }\n\n \/\/ \u8a8d\u8a3c\n install(Authentication) {\n session<SessionAccount>("session-auth") {\n data class AccountPrincipal(val id: Int) : Principal\n validate { sessionAccount ->\n transaction { AccountEntity.findByGoogleId(sessionAccount.googleId) }?.let {\n AccountPrincipal(it.id)\n }\n }\n challenge = SessionAuthChallenge.Unauthorized\n }\n }\n}<\/code><\/pre>\n
Rooting<\/h3>\n
\n
\/logged_in<\/code>\u304c\u547c\u3073\u51fa\u3055\u308c\u308b\u3002\n
\n
401 Unauthorized<\/code>\u3092\u8fd4\u5374\u3059\u308b\u3002<\/li>\n<\/ul>\n<\/li>\n
\/login<\/code>\u304c\u547c\u3073\u51fa\u3055\u308c\u308b\u3002\n
\n
401<\/code>\u306b\u306f\u306a\u3089\u306a\u3044\u3002<\/li>\n
id_token<\/code>\u3092\u53d7\u3051\u53d6\u308a\u3001\u8a8d\u8a3c\u51e6\u7406
signIn<\/code>\u3092\u547c\u3073\u51fa\u3059\u3002<\/li>\n
signIn<\/code>\u306e\u4e2d\u3067\u306f\u4ee5\u4e0b\u3092\u5b9f\u65bd\u3057\u3066\u3044\u308b\u3002\n
\n
id_token<\/code>\u3092\u5143\u306bGoogle OAuth\u306eAPI\u3092\u547c\u3073\u51fa\u3059\u3002<\/li>\n
200 OK<\/code>\u3092\u8fd4\u5374\u3059\u308b\u3002<\/li>\n<\/ul>\n<\/li>\n
\/hoge<\/code>\u3084
\/fuga<\/code>\u304c\u547c\u3073\u51fa\u3055\u308c\u308b\u3002\n
\n
validate<\/code>\u51e6\u7406\u3092\u901a\u308a\u629c\u3051\u3066\u3001\u30a2\u30d7\u30ea\u672c\u6765\u306e\u51e6\u7406\u304c\u5b9f\u884c\u3055\u308c\u308b\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n
routing {\n \/\/ \u30bb\u30c3\u30b7\u30e7\u30f3\u8a8d\u8a3c\u5bfe\u8c61\u5916\n get("\/login") {\n val idToken = call.parameters["id_token"]\n idToken ?: throw NotFoundException("idToken is not found")\n val clientId = application.environment.config.property("app.google.client_id").getString()\n\n call.respond(transaction { signIn(idToken, clientId, call.sessions) })\n }\n\n \/\/ \u30bb\u30c3\u30b7\u30e7\u30f3\u8a8d\u8a3c\u5bfe\u8c61\n authenticate("session-auth") {\n get("\/logged_in") {\n call.respondText("already logged in")\n }\n get("\/hoge") {\n \/\/ do something\n }\n get("\/fuga") {\n \/\/ do something\n }\n }\n}\n\nfun signIn(idToken: String, clientId: String, sessions: CurrentSession) {\n \/\/ idToken\u3092\u5229\u7528\u3057\u3066\u3001Google OAuth\u8a8d\u8a3c\u5b9f\u884c\n val verifier: GoogleIdTokenVerifier = GoogleIdTokenVerifier\n .Builder(NetHttpTransport(), JacksonFactory.getDefaultInstance())\n .setAudience(Collections.singletonList(clientId))\n .build()\n val token: GoogleIdToken = verifier.verify(idToken)\n\n \/\/ \u30e6\u30fc\u30b6\u60c5\u5831\u53d6\u5f97\n val googleId = token.payload.subject!!\n val googleName = token.payload.email!!\n\n \/\/ \u30a2\u30ab\u30a6\u30f3\u30c8\u304c\u306a\u3051\u308c\u3070\u30a2\u30ab\u30a6\u30f3\u30c8\u3092DB\u306b\u767b\u9332\n val account = AccountEntity.insertIfNotExists(googleId, googleName)\n\n \/\/ \u30bb\u30c3\u30b7\u30e7\u30f3\u60c5\u5831\u3092\u8ffd\u52a0\n sessions.set(SessionAccount(googleId, googleName))\n}<\/code><\/pre>\n
\u6240\u611f<\/h2>\n