Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] scopes comma-delimited to space-delimited #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
*.log
*.log
\.idea/
20 changes: 16 additions & 4 deletions dist/index.es.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,15 @@ class GoogleApi extends React.Component {
var _temp;

return _temp = super(...args), this.authorize = () => {
if (this.auth) {
this.auth.signIn();
if (this.auth && this.props.offline) {
if (this.props.offline) {
this.auth.grantOfflineAccess({
scope: `${this.props.scopes.join(' ')}`,
prompt: 'select_account'
}).then(({ code }) => this.setState({ code }));
}

if (!this.props.offline) this.auth.signIn();
}
}, this.signout = () => {
if (this.auth) {
Expand All @@ -29,7 +36,8 @@ class GoogleApi extends React.Component {
loading: true,
error: null,
authorize: this.authorize,
signout: this.signout
signout: this.signout,
code: null
}, _temp;
}

Expand All @@ -52,7 +60,9 @@ class GoogleApi extends React.Component {
apiKey: this.props.apiKey,
clientId: this.props.clientId,
discoveryDocs: this.props.discoveryDocs,
scope: this.props.scopes.join(',')
scope: this.props.scopes.join(' '),
fetch_basic_profile: this.props.profile,
redirect_uri: 'http://localhost:3000'
});
} catch (error) {
this.setState({
Expand Down Expand Up @@ -82,6 +92,8 @@ class GoogleApi extends React.Component {
GoogleApi.propTypes = {
clientId: PropTypes.string.isRequired,
apiKey: PropTypes.string.isRequired,
offline: PropTypes.bool,
profile: PropTypes.bool,
discoveryDocs: PropTypes.arrayOf(PropTypes.string).isRequired,
scopes: PropTypes.arrayOf(PropTypes.string).isRequired,
children: PropTypes.oneOfType([PropTypes.func, PropTypes.node])
Expand Down
20 changes: 16 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,15 @@ class GoogleApi extends React.Component {
var _temp;

return _temp = super(...args), this.authorize = () => {
if (this.auth) {
this.auth.signIn();
if (this.auth && this.props.offline) {
if (this.props.offline) {
this.auth.grantOfflineAccess({
scope: `${this.props.scopes.join(' ')}`,
prompt: 'select_account'
}).then(({ code }) => this.setState({ code }));
}

if (!this.props.offline) this.auth.signIn();
}
}, this.signout = () => {
if (this.auth) {
Expand All @@ -35,7 +42,8 @@ class GoogleApi extends React.Component {
loading: true,
error: null,
authorize: this.authorize,
signout: this.signout
signout: this.signout,
code: null
}, _temp;
}

Expand All @@ -58,7 +66,9 @@ class GoogleApi extends React.Component {
apiKey: this.props.apiKey,
clientId: this.props.clientId,
discoveryDocs: this.props.discoveryDocs,
scope: this.props.scopes.join(',')
scope: this.props.scopes.join(' '),
fetch_basic_profile: this.props.profile,
redirect_uri: 'http://localhost:3000'
});
} catch (error) {
this.setState({
Expand Down Expand Up @@ -88,6 +98,8 @@ class GoogleApi extends React.Component {
GoogleApi.propTypes = {
clientId: PropTypes.string.isRequired,
apiKey: PropTypes.string.isRequired,
offline: PropTypes.bool,
profile: PropTypes.bool,
discoveryDocs: PropTypes.arrayOf(PropTypes.string).isRequired,
scopes: PropTypes.arrayOf(PropTypes.string).isRequired,
children: PropTypes.oneOfType([PropTypes.func, PropTypes.node])
Expand Down
41 changes: 21 additions & 20 deletions dist/index.umd.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react')) :
typeof define === 'function' && define.amd ? define(['exports', 'react'], factory) :
(factory((global.ReactGoogleApi = {}),global.React));
}(this, (function (exports,React) { 'use strict';
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('@lourd/load-script')) :
typeof define === 'function' && define.amd ? define(['exports', 'react', '@lourd/load-script'], factory) :
(factory((global.ReactGoogleApi = {}),global.React,global.loadScript));
}(this, (function (exports,React,loadScript) { 'use strict';

React = React && React.hasOwnProperty('default') ? React['default'] : React;
loadScript = loadScript && loadScript.hasOwnProperty('default') ? loadScript['default'] : loadScript;

function createCommonjsModule(fn, module) {
return module = { exports: {} }, fn(module, module.exports), module.exports;
Expand Down Expand Up @@ -2335,18 +2336,6 @@ function createContext(defaultValue) {
};
}

function loadScript(url) {
return new Promise((resolve, reject) => {
const script = document.createElement('script');
script.onload = resolve;
script.onerror = reject;
script.src = url;
script.async = true;
script.type = 'text/javascript';
document.head.appendChild(script);
})
}

var _createContext = createContext(null);

const GoogleApiProvider = _createContext.Provider;
Expand All @@ -2360,8 +2349,15 @@ class GoogleApi extends React.Component {
var _temp;

return _temp = super(...args), this.authorize = () => {
if (this.auth) {
this.auth.signIn();
if (this.auth && this.props.offline) {
if (this.props.offline) {
this.auth.grantOfflineAccess({
scope: `${this.props.scopes.join(' ')}`,
prompt: 'select_account'
}).then(({ code }) => this.setState({ code }));
}

if (!this.props.offline) this.auth.signIn();
}
}, this.signout = () => {
if (this.auth) {
Expand All @@ -2373,7 +2369,8 @@ class GoogleApi extends React.Component {
loading: true,
error: null,
authorize: this.authorize,
signout: this.signout
signout: this.signout,
code: null
}, _temp;
}

Expand All @@ -2396,7 +2393,9 @@ class GoogleApi extends React.Component {
apiKey: this.props.apiKey,
clientId: this.props.clientId,
discoveryDocs: this.props.discoveryDocs,
scope: this.props.scopes.join(',')
scope: this.props.scopes.join(' '),
fetch_basic_profile: this.props.profile,
redirect_uri: 'http://localhost:3000'
});
} catch (error) {
this.setState({
Expand Down Expand Up @@ -2426,6 +2425,8 @@ class GoogleApi extends React.Component {
GoogleApi.propTypes = {
clientId: propTypes.string.isRequired,
apiKey: propTypes.string.isRequired,
offline: propTypes.bool,
profile: propTypes.bool,
discoveryDocs: propTypes.arrayOf(propTypes.string).isRequired,
scopes: propTypes.arrayOf(propTypes.string).isRequired,
children: propTypes.oneOfType([propTypes.func, propTypes.node])
Expand Down
2 changes: 1 addition & 1 deletion dist/index.umd.min.js

Large diffs are not rendered by default.

18 changes: 15 additions & 3 deletions modules/GoogleApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,23 @@ class GoogleApi extends React.Component {
static propTypes = {
clientId: PropTypes.string.isRequired,
apiKey: PropTypes.string.isRequired,
offline: PropTypes.bool,
profile: PropTypes.bool,
discoveryDocs: PropTypes.arrayOf(PropTypes.string).isRequired,
scopes: PropTypes.arrayOf(PropTypes.string).isRequired,
children: PropTypes.oneOfType([PropTypes.func, PropTypes.node]),
}

authorize = () => {
if (this.auth) {
this.auth.signIn()
if (this.auth && this.props.offline) {
if (this.props.offline) {
this.auth.grantOfflineAccess({
scope: `${this.props.scopes.join(' ')}`,
prompt: 'select_account'
}).then(({code }) => this.setState({ code }))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What should happen if the promise rejects?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also what is the code parameter here?

}

if (!this.props.offline) this.auth.signIn()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These blocks can be simplified:

if (this.auth) {
  if (this.props.offline) {
    // grantOfflineAccess
  } else {
    this.auth.signIn()
  }
}

}
}

Expand All @@ -38,6 +47,7 @@ class GoogleApi extends React.Component {
error: null,
authorize: this.authorize,
signout: this.signout,
code: null
}

componentDidMount() {
Expand All @@ -61,7 +71,9 @@ class GoogleApi extends React.Component {
apiKey: this.props.apiKey,
clientId: this.props.clientId,
discoveryDocs: this.props.discoveryDocs,
scope: this.props.scopes.join(','),
scope: this.props.scopes.join(' '),
fetch_basic_profile: this.props.profile,
redirect_uri: 'http://localhost:3000'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this.props.profile isn't set, what happens? redirect_uri should also be configurable by props

})
} catch (error) {
this.setState({
Expand Down
Loading