2017-07-27 454 views
0

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

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> 
    ); 
    } 
} 

回答

0

我可以看到的唯一的事可能会造成它是:

var auth0 = new Auth0(credentials); 

尝试注释这一行了,看看你的错误依然。

我还会检查以确保您粘贴了Auth0仪表板中的整个clientID。我很确定clientID缺少10个左右的字符。我的全部32个字符。

如果不起作用遵循什么明确张贴在这里:

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

+0

我从我的客户端ID拿出字符维护我公司的隐私和安全。如果我注释掉该行,应用程序将抛出“auth0 not defined”错误。 –

+0

对不起。我的意思是删除凭证参数 –

+0

我更改了我的代码,以便它反映了如何使用passwordRealm登录的react-native-auth0文档。我现在收到未经授权的错误消息。我希望它是因为我们还没有设置我们的ADFS服务器。 –