【问题标题】:Auth0 integration with Google Home - TypeScriptAuth0 与 Google Home 的集成 - TypeScript
【发布时间】:2019-11-20 10:46:32
【问题描述】:

我有 GoogleHome 的示例 (https://github.com/actions-on-google/smart-home-nodejs/blob/master/src/auth-provider.ts) 在 GCP 上运行 100%,只缺少 0Auth2 身份验证,并且 Auth0 提供的服务似乎是一个很好的解决方案,但在 TypeScript 中没有示例。

Actions on Google 配置正确,可以通过 Auth0 登录,但无法集成到示例中。

经过大量研究,我一直在兜圈子。 至少从库中导入不会失败。

import * as express from 'express'
import * as util from 'util'
import { Headers } from 'actions-on-google'
import createAuth0Client from '@auth0/auth0-spa-js';

import * as Firestore from './firestore'

/**
 * A function that gets the user id from an access token.
 * Replace this functionality with your own OAuth provider.
 *
 * @param headers HTTP request headers
 * @return The user id
 */
export async function getUser(headers: Headers): Promise<string> {
  const authorization = headers.authorization
  const accessToken = (authorization as string).substr(7)
  return await Firestore.getUserId(accessToken)
} ...

【问题讨论】:

  • 你到底遇到了什么问题?
  • 嗨尼克,我找到了你的 tutorial 并且无法让它工作,在线 const app = smarthome 说 smarthome 不是一个功能,所以我尝试了另一种方法使用 Auth0-spa-js 库,但我不知道该怎么做,Auth0 站点中没有 TypeScript 示例。我知道我缺少很多概念,但经过一番努力,我设法让 Google Home 示例完美运行,现在我必须实现 OAuth2 服务器。
  • 嗨,Dan,我在 Google Home 运行的示例中看到了这个文档:当我进入 Google 助理应用程序 -> 家庭自动化 -> “+” -> 我选择我的应用程序 -> 出现 Auth0 屏幕 -> 我登录,之后我应该收到令牌,但我在调整代码时迷路了,例如如何注册“端点”。当然,我缺乏对我的概念......

标签: typescript actions-on-google auth0 google-home


【解决方案1】:

已解决,经过一番努力,我能够在 TypeScript 中使用 Auth0 库:

import { AuthenticationClient } from 'auth0'

const auth0 = new AuthenticationClient({
   domain: '<my-domin-auth0>.auth0.com',
   clientId: '<clientId>',
   clientSecret: '<clientSecret>'
});

export async function getUser(headers: Headers): Promise<string> {       
   const authorization = headers.authorization
   const accessToken = (authorization as string).substr(7)
   const {email} = await auth0.getProfile(accessToken)
   console.log(email)
   return await Firestore.getUserId(accessToken)
}

我强烈推荐阅读@nick-felker 文章。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-29
    相关资源
    最近更新 更多