参数错误中缺少clientId

时间:2017-07-27 00:50:43

标签: react-native adfs auth0

我正在为我的公司开发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>
    );
  }
}

1 个答案:

答案 0 :(得分:0)

我能看到的唯一可能导致它的是:

var auth0 = new Auth0(credentials);

尝试评论此行,看看是否仍然出现错误。

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

如果这不起作用,请按照此处明确发布的内容进行操作:

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