首页 > 解决方案 > [错误:ExpoAppAuth.Get Auth:JSON 反序列化错误]

问题描述

使用“expo-app-auth”中的 AppAuth 时出错;

当我尝试 authi 得到以下错误:[错误:ExpoAppAuth.Get Auth:JSON 反序列化错误]

const config =  {   

  serviceConfiguration: {

  authorizationEndpoint: 'https://api.netatmo.com/oauth2/authorize',

  tokenEndpoint: 'https://api.netatmo.com/oauth2/token',
  },

  clientId: 'cilentid',

  clientSecret: 'cilentsecret',

  scopes: ['read_presence']

}

是不是和配置有关?

标签: react-nativeexpoappauth

解决方案


您的配置无效。

这与https://github.com/expo/expo/pull/5311中的问题有关- expo-app-auth 中的三元运算符中存在错误,该错误将滚入即将发布的版本中。同时,您必须在服务配置对象中为registrationEndpoint 指定一个虚拟值。

const config =  {   

  issuer: 'https://api.netatmo.com/oauth2/token',

  clientId: 'cilentid',

  clientSecret: 'cilentsecret',

  scopes: ['read_presence'],

  serviceConfiguration: {
        registrationEndpoint: 'https://example.com'
      }

}

如果不使用,您可以尝试其他方法。

您尝试并按照此链接上的型号npm install react-native-app-auth --save按照安装说明进行操作。

在此之前,您必须退出世博会。跑expo eject

例子

import { authorize } from 'react-native-app-auth';

const config = {
  issuer: 'https://api.netatmo.com/oauth2/token',
  clientId: 'cilentid',
  redirectUrl: 'https://api.netatmo.com/',
  scopes: ['read_presence'],
  clientSecret: 'cilentsecret'
};

const result = await authorize(config);

推荐阅读