Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License

Copyright (c) 2010-2019 Google, Inc. http://angularjs.org

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
29 changes: 21 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@ React component for [GitHub login](https://developer.github.com/v3/oauth/).
## Usage

```js
import React from 'react';
import ReactDOM from 'react-dom';
import GitHubLogin from 'react-github-login';
import React from "react";
import ReactDOM from "react-dom";
import GitHubLogin from "react-github-login";

const onSuccess = response => console.log(response);
const onFailure = response => console.error(response);

ReactDOM.render(
<GitHubLogin clientId="ac56fad434a3a3c1561e"
<GitHubLogin
clientId="client id goes here"
onSuccess={onSuccess}
onFailure={onFailure}/>,
document.getElementById('example')
onFailure={onFailure}
/>,
document.getElementById("example")
);
```

Expand Down Expand Up @@ -73,11 +75,22 @@ Callback for successful login. An object will be passed as an argument to the ca

Callback for errors raised during login.


## Development

```sh
$ npm start
```

Webpack development server starts at [http://localhost:8080](http://localhost:8080), loading [example/index.html](github.com/checkr/react-facebook-login/tree/master/example/index.html).
## Build

```sh
$ npm run build
```

## Lint

```sh
$ npm run lint
```

Webpack development server starts at [http://localhost:8080](http://localhost:8080).
69 changes: 31 additions & 38 deletions src/GitHubLogin.js
Original file line number Diff line number Diff line change
@@ -1,66 +1,59 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import React, { Component } from "react";
import { func, node, string } from "prop-types";

import PopupWindow from './PopupWindow';
import { toQuery } from './utils';
import PopupWindow from "./PopupWindow";
import { toQuery } from "./utils";

class GitHubLogin extends Component {
static propTypes = {
buttonText: PropTypes.string,
children: PropTypes.node,
className: PropTypes.string,
clientId: PropTypes.string.isRequired,
onRequest: PropTypes.func,
onSuccess: PropTypes.func,
onFailure: PropTypes.func,
redirectUri: PropTypes.string,
scope: PropTypes.string,
}
buttonText: string,
children: node,
className: string,
clientId: string.isRequired,
onRequest: func,
onSuccess: func,
onFailure: func,
redirectUri: string,
scope: string
};

static defaultProps = {
buttonText: 'Sign in with GitHub',
redirectUri: '',
scope: 'user:email',
buttonText: "Sign in with GitHub",
redirectUri: "",
scope: "user:email",
onRequest: () => {},
onSuccess: () => {},
onFailure: () => {},
}
onFailure: () => {}
};

onBtnClick = () => {
const { clientId, scope, redirectUri } = this.props;
const search = toQuery({
client_id: clientId,
scope,
redirect_uri: redirectUri,
redirect_uri: redirectUri
});
const popup = this.popup = PopupWindow.open(
'github-oauth-authorize',
const popup = (this.popup = PopupWindow.open(
"github-oauth-authorize",
`https://github.com/login/oauth/authorize?${search}`,
{ height: 1000, width: 600 }
);
));

this.onRequest();
popup.then(
data => this.onSuccess(data),
error => this.onFailure(error)
);
}
popup.then(data => this.onSuccess(data), error => this.onFailure(error));
};

onRequest = () => {
this.props.onRequest();
}
onRequest = () => this.props.onRequest();

onSuccess = (data) => {
onSuccess = data => {
if (!data.code) {
return this.onFailure(new Error('\'code\' not found'));
return this.onFailure(new Error("'code' not found"));
}

this.props.onSuccess(data);
}
};

onFailure = (error) => {
this.props.onFailure(error);
}
onFailure = error => this.props.onFailure(error);

render() {
const { className, buttonText, children } = this.props;
Expand All @@ -70,7 +63,7 @@ class GitHubLogin extends Component {
attrs.className = className;
}

return <button {...attrs}>{ children || buttonText }</button>;
return <button {...attrs}>{children || buttonText}</button>;
}
}

Expand Down