【问题标题】:Missing clientId in parameters error参数错误中缺少 clientId
【发布时间】:2018-01-02 12:34:25
【问题描述】:

我正在为我的公司开发一个 CRM 应用程序。我正在使用 auth0 库并尝试对 ADFS 进行身份验证。下面是代码: 当我按下登录按钮时,我收到错误“参数中缺少 clientId”。不知道我在这里缺少什么。任何帮助表示赞赏!我在创建新的 Auth0 并将其保存到 auth0 时输入了我的凭据。

export default class Login extends Component {
  constructor(props) {
    super(props);
  }
  state = {
    email: "",
    password: "",
    error: "",
    loading: false,
    loggedIn: null
  };

  onButtonPress() {
    const { email, password } = this.state;
    this.setState({
      email: { email },
      password: { password },
      error: "",
      loading: true,
      loggedIn: false
    });

    var auth0 = new Auth0(credentials);

    var webAuth = new auth0.WebAuth({
      domain: "crm.auth0.com",
      clientID: "6ZiWpn7DbTHVO2ktagE1h4"
    });

    // auth0
    //     .webAuth
    //     .authorize({scope: 'openid email', audience: 'https://issicrm.auth0.com/userinfo'})
    //     .then( credentials => console.log(credentials) )
    //     .catch(error => console.log(error));

    webAuth.client.login(
      {
        clientID: "6ZiWpn7DbTHVzjtO071y1h4",
        realm: "crm",
        username: { email },
        password: { password },
        scope: "openid profile",
        audience: "https://crm.auth0.com/userinfo"
      },
      function(err, authResult) {
        if (authResult) {
          // Save the tokens from the authResult
          // in local storage or a cookie
          alert("logged in!!");
          console.log(authResult);
          localStorage.setItem("access_token", authResult.accessToken);
          localStorage.setItem("id_token", authResult.idToken);
          this.onAuthSuccess();
        } else if (err) {
          console.log(err);
          this.onAuthFailed();
        }
      }
    );
  }

  onAuthSuccess() {
    this.setState({
      email: "",
      password: "",
      error: "",
      loading: false,
      loggedIn: true
    });
    this.props.succesHandler();
    navigate("SalesOrderList");
  }

  onAuthFailed() {
    this.setState({
      error: "Authentication Failed",
      loading: false,
      loggedIn: false
    });
    this.props.failureHandler();
  }

  render() {
    const { navigate } = this.props.navigation;
    const {
      form,
      fieldStyles,
      loginButtonArea,
      errorMessage,
      welcome,
      container
    } = styles;

    return (
      <View style={styles.container}>
        <Text style={styles.labelText}>Login to ISSI CRM</Text>
        <MKTextField
          text={this.state.email}
          onTextChange={email => this.setState({ email })}
          textInputStyle={fieldStyles}
          placeholder={"Email..."}
          tintColor={MKColor.Teal}
        />
        <MKTextField
          text={this.state.password}
          onTextChange={password => this.setState({ password })}
          textInputStyle={fieldStyles}
          placeholder={"Password..."}
          tintColor={MKColor.Teal}
          password={true}
        />
        <Text style={errorMessage}>
          {this.state.error}
        </Text>
        <View style={loginButtonArea}>
          <LoginButton onPress={this.onButtonPress.bind(this)} />
        </View>
      </View>
    );
  }
}

【问题讨论】:

    标签: react-native adfs auth0


    【解决方案1】:

    我能看到的唯一原因是:

    var auth0 = new Auth0(credentials);
    

    尝试将此行注释掉,看看是否仍然出现错误。

    我还会检查以确保您从 Auth0 仪表板粘贴了整个 clientID。我很确定 clientID 缺少大约 10 个字符左右。我的都是 32 个字符。

    如果这不起作用,请遵循此处明确发布的内容:

    https://auth0.com/docs/libraries/auth0js/v8

    【讨论】:

    • 我从我的 ClientID 中取出字符以保护我公司的隐私和安全。如果我注释掉该行,应用程序会抛出“auth0 not defined”错误。
    • 对不起。我的意思是删除凭据参数
    • 我更改了我的代码,使其反映了 react-native-auth0 文档中有关如何使用 passwordRealm 登录的内容。我现在收到未经授权的错误消息。我希望这是因为我们还没有设置我们的 ADFS 服务器。
    • 登录auth0网站后务必添加回调URL。
    • 知道了。明天早上我会这样做,然后告诉你进展如何。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多