Skip to content

Commit

Permalink
fix(login): browser login with password (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
emilio-im authored Oct 27, 2021
1 parent 5703cc0 commit 6bd1854
Showing 1 changed file with 75 additions and 25 deletions.
100 changes: 75 additions & 25 deletions src/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,38 +22,88 @@ const info: PlatformInfo = {
browserLogin: {
loginURL: 'https://slack.com/signin#/signin',
authCookieName: 'd',
runJSOnClose: 'JSON.stringify(__loginReturnValue)',
runJSOnLaunch: `
let __loginReturnValue = {}
// if (window.boot_data?.api_token) {
// __loginReturnValue.apiToken = window.boot_data?.api_token
// __loginReturnValue.teamID = window.boot_data?.team_id
// window.close()
// }
const handleButtonClick = (href) => {
__loginReturnValue.magicLink = href
setTimeout(() => window.close(), 1000)
}
runJSOnClose: 'JSON.stringify(window.__loginReturnValue)',
runJSOnNavigate: `
window.__loginReturnValue = {}
window.addEventListener('hashchange', function(){
const changeListener = function(){
const url = window.location.href
const form = document.getElementById('signin_form')
if (url.includes('signin')) {
const elements = document.querySelectorAll('[href*="login"]')
elements.forEach((element) => {
element.target = ''
if (form) {
const submitButton = document.getElementById('signin_btn')
const { href } = element
if (href.includes('login')) {
element.onclick = () => handleButtonClick(href)
element.removeAttribute('href')
submitButton.type = 'reset'
submitButton.onclick = async () => {
submitButton.classList.toggle('c-button--disabled')
const res = await fetch('/', {
"method": "POST",
"mode": "cors",
"credentials": "include",
"referrerPolicy": "no-referrer",
headers: {
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
"cache-control": "max-age=0",
"content-type": "application/x-www-form-urlencoded",
"sec-ch-ua": "\"Chromium\";v=\"94\", \"Google Chrome\";v=\"94\", \";Not A Brand\";v=\"99\"",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "\"macOS\"",
"sec-fetch-dest": "document",
"sec-fetch-mode": "navigate",
"sec-fetch-site": "same-origin",
"sec-fetch-user": "?1",
"upgrade-insecure-requests": "1"
},
body: new URLSearchParams(new FormData(form)).toString()
});
if (res.status === 302) {
window.__loginReturnValue.method = 'password'
setTimeout(() => window.close(), 1000)
}
// TODO: Implement for 2-fa
})
submitButton.classList.toggle('c-button--disabled')
}
}
})
}
const addNavigationListener = () => {
window.addEventListener('hashchange', changeListener)
}
addNavigationListener()
changeListener()
`,
runJSOnLaunch: `
window.__loginReturnValue = {}
const handleButtonClick = (href) => {
window.__loginReturnValue.magicLink = href
setTimeout(() => window.close(), 1000)
}
const addEventsListeners = () => {
window.addEventListener('hashchange', function(){
const url = window.location.href
if (url.includes('signin')) {
const elements = document.querySelectorAll('[href*="login"]')
elements.forEach((element) => {
element.target = ''
const { href } = element
if (href.includes('login')) {
element.onclick = () => handleButtonClick(href)
element.removeAttribute('href')
}
// TODO: Implement for 2-fa
})
}
})
}
addEventsListeners();
`,
},
reactions: {
Expand Down

0 comments on commit 6bd1854

Please sign in to comment.