使用Angular 6进行Auth0注册

时间:2018-09-05 22:54:07

标签: typescript authentication authorization angular6 auth0

我正在使用Angular 6开发原型,我想使用自定义API在Auth0上创建一个用户。我可以使用Auth0的signUp来注册新用户,但是根据要求,我不能使用它。我想在auth0上使用我的api创建一个用户。

有没有办法做到这一点?我遍历了auth0的文档,但无法正确完成。

PS:这只是一个原型,所以我已经实现了伪造的后端来执行此操作,但是我想使用auth0来实现。(我没有任何数据库或任何东西。只想实现login和signUp方法)

谁能告诉我我要去哪里错了?

我的代码:

HTML:

<form name="register_form" id="register_form" action="" method="POST" autocomplete="on" onsubmit="">
  <input type="text" id="firstname" class="fadeIn second" name="firstname" #firstname placeholder="{{ 'First Name' | translate }}"
    ng-model="firstname">
  <input type="text" id="lastName" class="fadeIn third" name="lastName" #lastname placeholder="{{ 'Last Name' | translate }}"
    ng-model="lastname">
  <input type="text" id="email" class="fadeIn second" name="email" #email placeholder="{{ 'Email' | translate }}"
    ng-model="username">
  <input type="password" id="password" class="fadeIn third" name="password" #password placeholder="{{ 'Password' | translate }}"
    ng-model="password">
  <input type="button" id="signup-button" class="fadeIn fourth" value="{{ 'Sign Up' | translate }}" (click)="signupUser($event, firstname.value, lastname.value, email.value, password.value)">
</form>

registration.ts:

  public signupUser(event: Event, firstname: string, lastname: string, email: string, password: string) {
    event.preventDefault();
    this.waitingForResponse = true;
    const headers = new HttpHeaders();
    headers.append('Content-Type', 'application/json');
    const credentials = {
      client_id: 'ID',
      email: email,
      password: password,
      connection: 'Username-Password-Authentication'
    };
    this.http.post('https://DOMAIN.auth0.com/dbconnections/signup', JSON.stringify(credentials), { headers: headers })
        .subscribe(
          (response: Response) => {
            console.log(response.json());
          }
        );

谢谢..

0 个答案:

没有答案