Actually make the login attempt to the well-known JMAP endpoint

This commit is contained in:
Eli Ribble 2024-08-27 10:48:49 -07:00
parent c6400d58d3
commit faca28f802
3 changed files with 28 additions and 11 deletions

13
package-lock.json generated
View File

@ -16,6 +16,7 @@
"@types/node": "^16.18.104", "@types/node": "^16.18.104",
"@types/react": "^18.3.3", "@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0", "@types/react-dom": "^18.3.0",
"base-64": "^1.0.0",
"bootstrap": "^5.3.3", "bootstrap": "^5.3.3",
"react": "^18.3.1", "react": "^18.3.1",
"react-bootstrap": "^2.10.4", "react-bootstrap": "^2.10.4",
@ -25,6 +26,7 @@
"web-vitals": "^2.1.4" "web-vitals": "^2.1.4"
}, },
"devDependencies": { "devDependencies": {
"@types/base-64": "^1.0.2",
"prettier": "3.3.3" "prettier": "3.3.3"
} }
}, },
@ -4051,6 +4053,12 @@
"@babel/types": "^7.20.7" "@babel/types": "^7.20.7"
} }
}, },
"node_modules/@types/base-64": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/@types/base-64/-/base-64-1.0.2.tgz",
"integrity": "sha512-uPgKMmM9fmn7I+Zi6YBqctOye4SlJsHKcisjHIMWpb2YKZRc36GpKyNuQ03JcT+oNXg1m7Uv4wU94EVltn8/cw==",
"dev": true
},
"node_modules/@types/body-parser": { "node_modules/@types/body-parser": {
"version": "1.19.5", "version": "1.19.5",
"resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.19.5.tgz", "resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.19.5.tgz",
@ -5540,6 +5548,11 @@
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
"integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw=="
}, },
"node_modules/base-64": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/base-64/-/base-64-1.0.0.tgz",
"integrity": "sha512-kwDPIFCGx0NZHog36dj+tHiwP4QMzsZ3AgMViUBKI0+V5n4U0ufTCUMhnQ04diaRI8EX/QcPfql7zlhZ7j4zgg=="
},
"node_modules/batch": { "node_modules/batch": {
"version": "0.6.1", "version": "0.6.1",
"resolved": "https://registry.npmjs.org/batch/-/batch-0.6.1.tgz", "resolved": "https://registry.npmjs.org/batch/-/batch-0.6.1.tgz",

View File

@ -11,6 +11,7 @@
"@types/node": "^16.18.104", "@types/node": "^16.18.104",
"@types/react": "^18.3.3", "@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0", "@types/react-dom": "^18.3.0",
"base-64": "^1.0.0",
"bootstrap": "^5.3.3", "bootstrap": "^5.3.3",
"react": "^18.3.1", "react": "^18.3.1",
"react-bootstrap": "^2.10.4", "react-bootstrap": "^2.10.4",
@ -44,6 +45,7 @@
] ]
}, },
"devDependencies": { "devDependencies": {
"@types/base-64": "^1.0.2",
"prettier": "3.3.3" "prettier": "3.3.3"
} }
} }

View File

@ -1,5 +1,6 @@
import "./App.css"; import "./App.css";
import "bootstrap/dist/css/bootstrap.min.css"; import "bootstrap/dist/css/bootstrap.min.css";
import * as base64 from "base-64";
//import MailboxList from "./Mailbox"; //import MailboxList from "./Mailbox";
import AuthModal from "./AuthModal"; import AuthModal from "./AuthModal";
@ -13,17 +14,18 @@ interface IAuth {
const App = () => { const App = () => {
const [state, setInternalState] = useState<IAuth | null>(null); const [state, setInternalState] = useState<IAuth | null>(null);
const fetchUserData = () => { const doLogin = (email: string, password: string) => {
fetch("https://jsonplaceholder.typicode.com/users") const domain = email.split("@")[1];
.then((response) => { const well_known_url = "https://" + domain + "/.well-known/jmap"
return response.json(); let headers = new Headers();
headers.append("Authorization", "Basic " + base64.encode(email + ":" + password));
fetch(well_known_url, {
method: "GET",
headers: headers,
}) })
.then((data) => { .then(response => response.json())
//setUsers(data) .then(data => console.log(data))
}); .catch(error => console.error(error));
};
const doLogin = (username: string, password: string) => {
alert("I be authin '" + username)
}; };
const loadAuth = () => { const loadAuth = () => {
const auth = localStorage.getItem("auth"); const auth = localStorage.getItem("auth");