-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
440 additions
and
37 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 |
---|---|---|
@@ -0,0 +1,82 @@ | ||
name: Release Candidate | ||
on: | ||
push: | ||
tags: | ||
- 'v*-b*' | ||
|
||
jobs: | ||
Linux: | ||
runs-on: ubuntu-latest | ||
env: | ||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
GOOGLE_CLIENT_ID: ${{ secrets.GOOGLE_CLIENT_ID }} | ||
GOOGLE_CLIENT_SECRET: ${{ secrets.GOOGLE_CLIENT_SECRET }} | ||
steps: | ||
- uses: actions/checkout@master | ||
- uses: actions/setup-node@master | ||
with: | ||
node-version: "18" | ||
cache: "yarn" | ||
# See https://github.com/nodejs/node-gyp/blob/main/docs/Force-npm-to-use-global-node-gyp.md | ||
# https://github.com/nodejs/node-gyp/blob/main/docs/Updating-npm-bundled-node-gyp.md | ||
# - name: Update node-gyp | ||
# run: | | ||
# npm install --global [email protected] | ||
# npm config set node_gyp $(npm prefix -g)/lib/node_modules/node-gyp/bin/node-gyp.js | ||
- name: Install dependencies | ||
run: yarn install --immutable | ||
- name: Build and Release | ||
run: yarn release | ||
|
||
MacOs: | ||
runs-on: macos-13 | ||
env: | ||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
CSC_KEY_PASSWORD: ${{ secrets.CSC_KEY_PASSWORD }} | ||
CSC_LINK: ${{ secrets.CSC_LINK }} | ||
AC_USERNAME: ${{ secrets.AC_USERNAME }} | ||
AC_PASSWORD: ${{ secrets.AC_PASSWORD }} | ||
AC_TEAM_ID: ${{ secrets.AC_TEAM_ID }} | ||
GOOGLE_CLIENT_ID: ${{ secrets.GOOGLE_CLIENT_ID }} | ||
GOOGLE_CLIENT_SECRET: ${{ secrets.GOOGLE_CLIENT_SECRET }} | ||
steps: | ||
- uses: actions/checkout@master | ||
- uses: actions/setup-node@master | ||
with: | ||
node-version: "18" | ||
cache: "yarn" | ||
- name: Configure Node | ||
run: | | ||
# npm v9 doesn't allow custom config parameters (i.e. node_gyp) anymode, so we have to downgrade it to v8 | ||
npm install -g npm@8 | ||
npm install -g node-gyp@latest | ||
npm config set node_gyp $(npm prefix -g)/lib/node_modules/node-gyp/bin/node-gyp.js | ||
- name: Install dependencies | ||
run: yarn install --immutable | ||
- name: Build and Release | ||
run: yarn release | ||
|
||
Windows: | ||
runs-on: windows-2019 | ||
env: | ||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
CSC_KEY_PASSWORD: ${{ secrets.CSC_KEY_PASSWORD }} | ||
CSC_LINK: ${{ secrets.CSC_LINK }} | ||
GOOGLE_CLIENT_ID: ${{ secrets.GOOGLE_CLIENT_ID }} | ||
GOOGLE_CLIENT_SECRET: ${{ secrets.GOOGLE_CLIENT_SECRET }} | ||
steps: | ||
- uses: actions/checkout@master | ||
- uses: actions/setup-node@master | ||
with: | ||
node-version: "18" | ||
- name: Configure Node | ||
shell: powershell | ||
run: | | ||
# npm v9 doesn't allow custom config parameters (i.e. node_gyp) anymode, so we have to downgrade it to v8 | ||
npm install -g npm@8 | ||
npm install -g node-gyp@latest | ||
npm prefix -g | % {npm config set node_gyp "$_\node_modules\node-gyp\bin\node-gyp.js"} | ||
- name: Install dependencies | ||
run: yarn install --immutable | ||
- name: Build and Release | ||
run: yarn release |
Binary file not shown.
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
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
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
14 changes: 8 additions & 6 deletions
14
packages/app/src/services/services/electron-google-oauth/interface.ts
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,15 +1,17 @@ | ||
import { Schema$Person } from 'googleapis/build/src/apis/plus/v1'; | ||
import { people_v1 } from 'googleapis/build/src/apis/people/v1'; | ||
import { ServiceBase } from '../../lib/class'; | ||
import { service, timeout } from '../../lib/decorator'; | ||
import { RPC } from '../../lib/types'; | ||
import { Credentials } from 'google-auth-library/build/src/auth/credentials'; | ||
import { Credentials } from 'google-auth-library'; | ||
|
||
export type ElectronGoogleSignInResponse = { | ||
tokens: Credentials, | ||
profile: people_v1.Schema$Person, | ||
} | ||
|
||
@service('electron-google-oauth') | ||
export class ElectronGoogleOAuthService extends ServiceBase implements RPC.Interface<ElectronGoogleOAuthService> { | ||
@timeout(0) | ||
// @ts-ignore | ||
signIn(scopes: string[], forceAddSession?: boolean): Promise<{ | ||
tokens: Credentials, | ||
profile: Schema$Person, | ||
}> {} | ||
signIn(scopes: string[], forceAddSession?: boolean): Promise<ElectronGoogleSignInResponse> {} | ||
} |
86 changes: 75 additions & 11 deletions
86
packages/app/src/services/services/electron-google-oauth/main.ts
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,31 +1,95 @@ | ||
import { google } from 'googleapis'; | ||
import { people_v1 } from 'googleapis/build/src/apis/people/v1'; | ||
import { Credentials } from 'google-auth-library'; | ||
import ElectronGoogleOAuth2 from '@getstation/electron-google-oauth2'; | ||
import log from 'electron-log'; | ||
|
||
import { RPC } from '../../lib/types'; | ||
import { ElectronGoogleOAuthService } from './interface'; | ||
import { ElectronGoogleOAuthService, ElectronGoogleSignInResponse } from './interface'; | ||
|
||
const CLIENT_ID = process.env.GOOGLE_CLIENT_ID!; | ||
const CLIENT_SECRET = process.env.GOOGLE_CLIENT_SECRET!; | ||
|
||
export class ElectronGoogleOAuthServiceImpl extends ElectronGoogleOAuthService implements RPC.Interface<ElectronGoogleOAuthService> { | ||
async signIn(scopes: string[], forceAddSession?: boolean) { | ||
async signIn(scopes: string[], forceAddSession?: boolean): Promise<ElectronGoogleSignInResponse> { | ||
|
||
const client = new ElectronGoogleOAuth2(CLIENT_ID, CLIENT_SECRET, scopes, { successRedirectURL: 'https://getstation.com/' }); | ||
return client.openAuthWindowAndGetTokens(forceAddSession) | ||
.then(async (tokens) => { | ||
|
||
const service = google.people({ | ||
try { | ||
const service = google.people({ | ||
version: 'v1', | ||
auth: client.oauth2Client, | ||
}); | ||
}); | ||
|
||
const response = await service.people.get({ | ||
resourceName: 'people/me', | ||
personFields: 'names,emailAddresses,photos', | ||
sources: ['READ_SOURCE_TYPE_PROFILE'], | ||
}); | ||
const response = await service.people.get({ | ||
resourceName: 'people/me', | ||
personFields: 'names,emailAddresses,photos', | ||
sources: ['READ_SOURCE_TYPE_PROFILE'], | ||
}); | ||
|
||
return { tokens, profile: response.data as people_v1.Schema$Person }; | ||
return { tokens, profile: response.data as people_v1.Schema$Person }; | ||
} | ||
catch (err) { | ||
log.error(`Google profile request error ${err}`); | ||
return this.parseToken(tokens); | ||
} | ||
}); | ||
} | ||
|
||
private parseToken(tokens: Credentials): ElectronGoogleSignInResponse { | ||
try { | ||
//vk: id_token format https://developers.google.com/identity/gsi/web/reference/js-reference#credential | ||
const decodedStr = Buffer.from(tokens.id_token!.split('.')[1], 'base64').toString() | ||
const tokenPayload = JSON.parse(decodedStr); | ||
|
||
return { | ||
tokens, | ||
profile: { | ||
names: [ | ||
{ | ||
metadata: { | ||
source: { | ||
id: tokenPayload.sub, | ||
} | ||
}, | ||
displayName: tokenPayload.name, | ||
givenName: tokenPayload.given_name, | ||
familyName: tokenPayload.family_name, | ||
} | ||
], | ||
emailAddresses: [ | ||
{ | ||
type: '', | ||
value: tokenPayload.email, | ||
} | ||
], | ||
photos: [ | ||
{ | ||
url: tokenPayload.picture, | ||
} | ||
] | ||
} | ||
}; | ||
} | ||
catch (err) { | ||
log.error(`Parse token error ${err}`); | ||
return { | ||
tokens, | ||
profile: { | ||
names: [ | ||
{ | ||
displayName: 'unknown', | ||
} | ||
], | ||
emailAddresses: [ | ||
{ | ||
type: '', | ||
value: 'unknown', | ||
} | ||
] | ||
} | ||
}; | ||
}; | ||
} | ||
} |
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
Oops, something went wrong.