Auth0与Google Home-TypeScript的集成
我让GoogleHome的示例()在GCP上100%运行,只是缺少0Auth2身份验证,Auth0提供的服务似乎是一个很好的解决方案,但在TypeScript中没有示例 Google上的操作配置正确,我可以通过Auth0登录,但无法集成到示例中 经过大量研究,我一直在兜圈子。 至少从库导入不会失败Auth0与Google Home-TypeScript的集成,typescript,actions-on-google,auth0,google-home,Typescript,Actions On Google,Auth0,Google Home,我让GoogleHome的示例()在GCP上100%运行,只是缺少0Auth2身份验证,Auth0提供的服务似乎是一个很好的解决方案,但在TypeScript中没有示例 Google上的操作配置正确,我可以通过Auth0登录,但无法集成到示例中 经过大量研究,我一直在兜圈子。 至少从库导入不会失败 import * as express from 'express' import * as util from 'util' import { Headers } from 'actions-on-
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)
} ...
从“express”导入*为express
从“util”导入*作为util
从“谷歌上的操作”导入{Headers}
从“@auth0/auth0”导入CreateAuth0客户端;
将*作为Firestore从“/Firestore”导入
/**
*从访问令牌获取用户id的函数。
*用您自己的OAuth提供程序替换此功能。
*
*@param头HTTP请求头
*@返回用户id
*/
导出异步函数getUser(headers:headers):Promise{
const authorization=headers.authorization
const accessToken=(授权为字符串).substr(7)
return wait Firestore.getUserId(accessToken)
} ...
解决了,经过多次战斗,我能够在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)
}
从“auth0”导入{AuthenticationClient}
const auth0=新的AuthenticationClient({
域:'.auth0.com',
客户端ID:“”,
clientSecret:'
});
导出异步函数getUser(头:头):承诺{
const authorization=headers.authorization
const accessToken=(授权为字符串).substr(7)
const{email}=wait auth0.getProfile(accessToken)
控制台日志(电子邮件)
return wait Firestore.getUserId(accessToken)
}
我强烈建议阅读@nick felker的文章。解决了问题,经过多次斗争,我能够在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)
}
从“auth0”导入{AuthenticationClient}
const auth0=新的AuthenticationClient({
域:'.auth0.com',
客户端ID:“”,
clientSecret:'
});
导出异步函数getUser(头:头):承诺{
const authorization=headers.authorization
const accessToken=(授权为字符串).substr(7)
const{email}=wait auth0.getProfile(accessToken)
控制台日志(电子邮件)
return wait Firestore.getUserId(accessToken)
}
我强烈建议您阅读@nick felker的文章。您到底遇到了什么问题?嗨,nick,我找到了您的,但无法使其工作,在
const app=smarthome
一行中说smarthome不是一个函数,所以我尝试了另一种方法使用Auth0 spa js库,但我不知道如何做到这一点,Auth0站点中没有TypeScript示例。我知道我缺少很多概念,但经过一番努力,我成功地使Google Home示例完美工作,现在我必须实现OAuth2服务器。这有什么问题:嗨,Dan,我看到了这个文档,在我从Google Home运行的示例中:当我进入Google Assistant应用程序->Home Automation->我选择我的应用程序->出现Auth0屏幕->我登录,之后我应该会收到令牌,但我会丢失代码,例如如何注册“端点”。当然,我缺乏概念…你到底遇到了什么问题?嗨,尼克,我找到了你的,但无法使它工作,在const-app=smarthome
一行中说smarthome不是一个函数,所以我尝试了另一种方法来使用Auth0 spa-js库,但我不知道怎么做,Auth0站点中没有TypeScript示例。我知道我缺少很多概念,但经过一番努力,我成功地使Google Home示例完美工作,现在我必须实现OAuth2服务器。这有什么问题:嗨,Dan,我看到了这个文档,在我从Google Home运行的示例中:当我进入Google Assistant应用程序->Home Automation->我选择我的应用程序->出现Auth0屏幕->我登录,之后我应该会收到令牌,但我会丢失代码,例如如何注册“端点”。当然,我对自己缺乏概念。。。