Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Authentication 自定义身份验证AngularFire2 Ionic2_Authentication_Angular_Angularfire_Ionic2_Custom Authentication - Fatal编程技术网

Authentication 自定义身份验证AngularFire2 Ionic2

Authentication 自定义身份验证AngularFire2 Ionic2,authentication,angular,angularfire,ionic2,custom-authentication,Authentication,Angular,Angularfire,Ionic2,Custom Authentication,我将我的应用程序从Ionic 1更新为Ionic 2。 对于第一个应用程序(Ionic 1),我使用AngularFire和自定义身份验证(使用Slim框架)。对于Ionic 2,我尝试对AngularFire2(和firebase 2.4.2)执行相同的操作,但在对firebase进行身份验证时出现了此错误 代码(App.ts): 错误(在控制台中): 来自firebase/php jwt的代码: <?php use \Firebase\JWT\JWT; $key = "example

我将我的应用程序从Ionic 1更新为Ionic 2。 对于第一个应用程序(Ionic 1),我使用AngularFire和自定义身份验证(使用Slim框架)。对于Ionic 2,我尝试对AngularFire2(和firebase 2.4.2)执行相同的操作,但在对firebase进行身份验证时出现了此错误

代码(App.ts):

错误(在控制台中):

来自firebase/php jwt的代码:

<?php
use \Firebase\JWT\JWT;

$key = "example_key";
$token = array(
    "iss" => "http://example.org",
    "aud" => "http://example.com",
    "iat" => 1356999524,
    "nbf" => 1357000000
);

/**
 * IMPORTANT:
 * You must specify supported algorithms for your application. See
 * https://tools.ietf.org/html/draft-ietf-jose-json-web-algorithms-40
 * for a list of spec-compliant algorithms.
 */
$jwt = JWT::encode($token, $key);
$decoded = JWT::decode($jwt, $key, array('HS256'));

print_r($decoded);

/*
 NOTE: This will now be an object instead of an associative array. To get
 an associative array, you will need to cast it as such:
*/

$decoded_array = (array) $decoded;

/**
 * You can add a leeway to account for when there is a clock skew times between
 * the signing and verifying servers. It is recommended that this leeway should
 * not be bigger than a few minutes.
 *
 * Source: http://self-issued.info/docs/draft-ietf-oauth-json-web-token.html#nbfDef
 */
JWT::$leeway = 60; // $leeway in seconds
$decoded = JWT::decode($jwt, $key, array('HS256'));

?>


需要您的帮助。

您的令牌是一个字符串,对吗?
我们只是遇到了同样的错误,不得不调试源代码。
我们意识到,
this.af.auth.login
方法正在等待两个参数

简单地说,使用以下内容:
this.af.auth.login(令牌,{})

干杯,
Marcell

您的令牌是字符串,对吗?
我们只是遇到了同样的错误,不得不调试源代码。
我们意识到,
this.af.auth.login
方法正在等待两个参数

简单地说,使用以下内容:
this.af.auth.login(令牌,{})

干杯,
Marcell

这应该可以解决您的问题:

      this.af.auth.login(data.token, {
        provider: AuthProviders.Custom,
        method: AuthMethods.CustomToken
      })
        .then(data => {
          console.log(data);
        })
        .catch(error => {
          console.log(error);
        });

干杯。

这将解决您的问题:

      this.af.auth.login(data.token, {
        provider: AuthProviders.Custom,
        method: AuthMethods.CustomToken
      })
        .then(data => {
          console.log(data);
        })
        .catch(error => {
          console.log(error);
        });
干杯

<?php
use \Firebase\JWT\JWT;

$key = "example_key";
$token = array(
    "iss" => "http://example.org",
    "aud" => "http://example.com",
    "iat" => 1356999524,
    "nbf" => 1357000000
);

/**
 * IMPORTANT:
 * You must specify supported algorithms for your application. See
 * https://tools.ietf.org/html/draft-ietf-jose-json-web-algorithms-40
 * for a list of spec-compliant algorithms.
 */
$jwt = JWT::encode($token, $key);
$decoded = JWT::decode($jwt, $key, array('HS256'));

print_r($decoded);

/*
 NOTE: This will now be an object instead of an associative array. To get
 an associative array, you will need to cast it as such:
*/

$decoded_array = (array) $decoded;

/**
 * You can add a leeway to account for when there is a clock skew times between
 * the signing and verifying servers. It is recommended that this leeway should
 * not be bigger than a few minutes.
 *
 * Source: http://self-issued.info/docs/draft-ietf-oauth-json-web-token.html#nbfDef
 */
JWT::$leeway = 60; // $leeway in seconds
$decoded = JWT::decode($jwt, $key, array('HS256'));

?>
      this.af.auth.login(data.token, {
        provider: AuthProviders.Custom,
        method: AuthMethods.CustomToken
      })
        .then(data => {
          console.log(data);
        })
        .catch(error => {
          console.log(error);
        });