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
3 changes: 2 additions & 1 deletion packages/auth/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"AWSRoleSessionName": "webide",
"AWSRegion": "cn-north-1",
"GithubClientId": "0719e502c798dd4bb376",
"TencentClientId": "100017401279"
"TencentClientId": "100017401279",
"BSNClientId": ""
}
6 changes: 3 additions & 3 deletions packages/auth/src/Auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,21 @@ export default {
return !!this.username
},

async login (history, provider = 'github') {
async login (history, provider = 'github', state) {
if (!providers[provider]) {
return
}
if (platform.isDesktop) {
const channel = new IpcChannel('auth')
const loginUrl = providers[provider].loginUrl
const callbackUrl = await channel.invoke('login', { loginUrl, serverUrl })
const callbackUrl = await channel.invoke('login', { loginUrl, serverUrl, state })
if (callbackUrl) {
await this.handleCallback({ location: new URL(callbackUrl), provider, history })
}
this.updateProfile()
await channel.invoke('close')
} else {
providers[provider].login()
providers[provider].login(state)
}
},

Expand Down
23 changes: 23 additions & 0 deletions packages/auth/src/providers/bsn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { BSNClientId } from '../../config.json'

const project = process.env.PROJECT
const serverUrl = process.env.REACT_APP_SERVER_URL
const clientId = process.env.REACT_APP_BSN_CLIENT_ID || BSNClientId
const redirectUri = `${serverUrl}/api/v1/auth/callback/${project}/bsn`

export default {
login (state) {
window.location.href = `${this.loginUrl}&state=${this.formatState(state)}`
},
formatState (state) {
const stateString = JSON.stringify(state)
return encodeURIComponent(btoa(stateString))
},
restoreState (raw) {
const stateString = atob(decodeURIComponent(raw))
return JSON.parse(stateString)
},
get loginUrl() {
return `https://bsn.com/oauth/authorize?response_type=code&client_id=${clientId}&scope=all&redirect_uri=${redirectUri}`
}
}