-
-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Implement OAuth sign in - Stub of sync backend
- Loading branch information
1 parent
f315500
commit c71bf71
Showing
9 changed files
with
225 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
REACT_APP_DROPBOX_CLIENT_ID=your_dropbox_client_id | ||
REACT_APP_GOOGLE_DRIVE_API_KEY=your_google_drive_api_key | ||
REACT_APP_GOOGLE_DRIVE_CLIENT_ID=your_google_drive_oauth_client_id | ||
REACT_APP_GOOGLE_DRIVE_CLIENT_ID=your_google_drive_oauth_client_id | ||
REACT_APP_GITLAB_CLIENT_ID=your_gitlab_client_id | ||
REACT_APP_GITLAB_SECRET=your_gitlab_secret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ tags | |
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
/.log/ | ||
|
||
*~ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* global process */ | ||
import { OAuth2AuthCodePKCE } from '@bity/oauth2-auth-code-pkce'; | ||
import { isEmpty } from 'lodash'; | ||
|
||
export const createGitlabOAuth = () => | ||
new OAuth2AuthCodePKCE({ | ||
authorizationUrl: 'https://gitlab.com/oauth/authorize', | ||
tokenUrl: 'https://gitlab.com/oauth/token', | ||
clientId: process.env.REACT_APP_GITLAB_CLIENT_ID, | ||
redirectUrl: window.location.origin, | ||
scopes: ['api'], | ||
extraAuthorizationParams: { | ||
clientSecret: process.env.REACT_APP_GITLAB_SECRET, | ||
}, | ||
extraRefreshParams: { | ||
clientSecret: process.env.REACT_APP_GITLAB_SECRET, | ||
}, | ||
onAccessTokenExpiry: (refreshToken) => refreshToken(), | ||
onInvalidGrant: (refreshAuthCodeOrToken) => refreshAuthCodeOrToken(), | ||
}); | ||
|
||
/** | ||
* @param {OAuth2AuthCodePKCE} oauthClient | ||
*/ | ||
export default (oauthClient) => { | ||
const decoratedFetch = oauthClient.decorateFetchHTTPClient(fetch); | ||
|
||
const isSignedIn = () => new Promise((resolve) => resolve(oauthClient.isAuthorized())); | ||
|
||
// FIXME stub | ||
const getDirectoryListing = (path) => | ||
new Promise((resolve) => | ||
resolve({ | ||
listing: [], | ||
hasMore: false, | ||
}) | ||
); | ||
|
||
// FIXME stub | ||
const getMoreDirectoryListing = (additionalSyncBackendState) => | ||
new Promise((resolve) => | ||
resolve({ | ||
listing: [], | ||
hasMore: false, | ||
}) | ||
); | ||
|
||
// FIXME stub | ||
const updateFile = (path, contents) => new Promise((resolve) => resolve()); | ||
|
||
// FIXME stub | ||
const createFile = (path, contents) => new Promise((resolve) => resolve()); | ||
|
||
// FIXME stub | ||
const getFileContentsAndMetadata = (path) => | ||
new Promise((resolve) => | ||
resolve({ | ||
contents: '* FIXME', | ||
lastModifiedAt: new Date(), | ||
}) | ||
); | ||
|
||
// FIXME stub | ||
const getFileContents = (path) => { | ||
if (isEmpty(path)) return Promise.reject('No path given'); | ||
return new Promise((resolve, reject) => | ||
getFileContentsAndMetadata(path) | ||
.then(({ contents }) => resolve(contents)) | ||
.catch(reject) | ||
); | ||
}; | ||
|
||
// FIXME stub | ||
const deleteFile = (path) => new Promise((resolve) => resolve()); | ||
|
||
return { | ||
type: 'Dropbox', | ||
isSignedIn, | ||
getDirectoryListing, | ||
getMoreDirectoryListing, | ||
updateFile, | ||
createFile, | ||
getFileContentsAndMetadata, | ||
getFileContents, | ||
deleteFile, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters