oauth-io / oauth-phonegap

OAuth.io plugin for Apache Cordova/PhoneGap
195 stars 69 forks source link

InvalidHeaders #11

Closed theCarrotcakeMan closed 10 years ago

theCarrotcakeMan commented 10 years ago

I implemented a login dialog for my phonegap app but when I click the button that triggers the Oauth.popup the following error appears: Cannot find hostname in file:/// from static code: InvalidHeader message: Cannot find hostname in file:/// from static It works perfectly in the browser and in Android but I can't get it working with ios

bumpmann commented 10 years ago

Hello,

it looks like you are using the oauth-js version instead of the oauth-phonegap version.

If you are not sure, you can check that OAuth.getVersion() gives you something like phonegap-* (and not web-*)

adelevie commented 10 years ago

I'm getting this using oauth.js on a web app.

index.html:

<html>
  <head>
    <link href="http://netdna.bootstrapcdn.com/bootswatch/3.1.1/cosmo/bootstrap.min.css" rel="stylesheet">
    <script src="bower_components/jquery/dist/jquery.min.js"></script>
    <script src="bower_components/oauth-js/dist/oauth.js"></script>
  </head>
  <body>
....

app.jsx (using fb react):

var GitHubLogin = React.createClass({
  getInitialState: function () {
    return {
      'loggedIn': false
    };
  },
  logIn: function(event) {
    //alert("logging in");
    //this.setState({loggedIn: true});
    alert("ugh");
    OAuth.popup('github', function(err, result) {
      if (!err) {
        this.setState({loggedIn: true});
        this.props.accessToken = result.access_token;
      } else {
        alert("There was an error.");
      }
    });
  },
  logOut: function(event) {
    //alert("logging out");
    this.setState({loggedIn: false});
  },
  render: function() {
    var logInButton = <button onClick={this.logIn}>Log in with GitHub</button>;
    var logOutButton = <button onClick={this.logOut}>Logout from GitHub</button>;
    if (!this.state.loggedIn) {
      return logInButton;
    } else {
      return logOutButton;
    }
  }
});

// last but not least, this actually mounts the React components to the DOM

React.renderComponent(
  <Container>
    <GitHubLogin />
    <MarkdownEditor />
  </Container>,
  document.getElementById("content")
);
william26 commented 10 years ago

It seems you installed oauth-js, our browser JavaScript SDK through bower. To use our oauth-phonegap SDK, you need to install it like this in your phonegap/cordova project :

$ cordova plugin add https://github.com/oauth-io/oauth-phonegap

Please note that we are working on the soon to be released version 0.2.0 of the Phonegap SDK, which will bring fixes and new features. If you want to check it out, feel free to take a look at our develop branch.

I hope this helps :)

Edit (06-04-2014) : We released version 0.2.0 today.

ravipothkunuri commented 10 years ago

Hi William,i installed oauth phonegap plugin like

$ phonegap plugin add https://github.com/oauth-io/oauth-phonegap

iam also facing same problem like cannot find host name in file:///

hope you will reply back soon

striddleapp commented 10 years ago

I am having the same issue as ravipothkunuri

I am still getting the web version returned back to me. Is there a way to override the JS SDK with the Phonegap one?

theCarrotcakeMan commented 10 years ago

It seems like you're still loading the web version. Install the phonegap specific plugin as ravipothkunuri said, but be sure you're not including any js file for oauth. The plugin should load OAuth.io to window when the app is launched