使用 js.dart 公开 auth0 API [英] using js.dart to expose auth0 API

查看:23
本文介绍了使用 js.dart 公开 auth0 API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个 Dart Angular2 应用程序,但它与手头的问题无关.

I'm writing an Dart Angular2 application but it's irrelevant to the problem at hand.

我试图通过使用 1https://pub.dartlang.org/packages/js 公开它的 API 来将 Auth0Lock 与 dart 一起使用.

I'm trying to use Auth0Lock with dart by exposing it's API using 1https://pub.dartlang.org/packages/js.

我正在使用 Dartium 调试应用程序.

I'm using Dartium to debug the application.

所以我使用以下 auth0lock.dart 文件公开 Auth0Lock API:

so I'm exposing the Auth0Lock API using the following auth0lock.dart file:

import 'package:js/js.dart';

@JS()
class Auth0Lock {
 external factory Auth0Lock(String token, String domain, Object options);
  external on(String event, Function func);
  external show();
}

我只公开了我需要的基本内容.

I exposed only the basic stuff I need.

然后我在名为 auth0_service.dart 的文件中创建了一个 Angular2 服务,该文件具有以下代码:

then I created an Angular2 service in a file named auth0_service.dart that has the following code:

import 'package:angular2/core.dart';导入 'auth0lock.dart';导入'app.config.dart';

import 'package:angular2/core.dart'; import 'auth0lock.dart'; import 'app.config.dart';

@Injectable()
class Auth {
Auth0Lock lock;

Auth() {
    this.lock = new Auth0Lock(configObj.auth0.apiKey, configObj.auth0.domain,{});
}
updateProfileName(data) {
  var profile = data['profile'] != null ? data['profile'] : data;
  print(profile['name']);
}

authenticated() {
  return false;
}

login() {
    this.lock.show().then(this.updateProfileName);
}


}

我还将显示我的 index.html 加载 auth0 的位置:

I'll also show my index.html where I load auth0:

<!DOCTYPE html>
<html>
<head>
    <title>Demo App</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
    <link rel="stylesheet" href="www/styles.css">
    <script src="https://cdn.auth0.com/js/lock/10.0.0/lock.min.js"></script>
    <script defer src="/web/main.dart" type="application/dart"></script>
    <script defer src="/packages/browser/dart.js"></script>
</head>
<body>
    <my-app></my-app>
</body>
</html>

当我运行我的应用程序时,出现以下错误:

when I run my application I get the ollowing error:

EXCEPTION: No static method 'Auth0Lock.' declared in class 'Auth0Lock'.

所以 Auth0Lock 不是静态方法,它是类的构造函数.所以我必须以某种方式错误地使用 JS api.

so Auth0Lock is not a static method, it's a constructor for the class. so I must used the JS api wrong somehow.

推荐答案

我需要在 auth0lock.dart 前面加上以下内容:

i need to prepend to the auth0lock.dart the following:

@JS()
library test;

实际上我可以将 test 重命名为任何我想要的...我只需要添加带有名称的 js 标签和库.解决了它.

actually I can rename test to anything I want... iI just need to add the js tag and library with a name. that solved it.

这篇关于使用 js.dart 公开 auth0 API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆