mirror of
https://github.com/openziti/zrok.git
synced 2024-12-22 23:02:52 +01:00
api authentiation roughed in (#18)
This commit is contained in:
parent
1f4c697a2a
commit
56243956da
@ -1,19 +1,15 @@
|
||||
import Login from './Login';
|
||||
import Logout from './Logout';
|
||||
import Version from './Version';
|
||||
import * as gateway from "./api/gateway";
|
||||
import {useEffect, useState} from "react";
|
||||
|
||||
gateway.init({
|
||||
url: '/api/v1'
|
||||
});
|
||||
import Identities from "./Identities";
|
||||
|
||||
const App = () => {
|
||||
const [user, setUser] = useState();
|
||||
|
||||
useEffect(() => {
|
||||
const localUser = localStorage.getItem("user")
|
||||
if(localUser) {
|
||||
if (localUser) {
|
||||
setUser(JSON.parse(localUser))
|
||||
console.log('reloaded user', localUser)
|
||||
}
|
||||
@ -32,10 +28,14 @@ const App = () => {
|
||||
<header className="zrok-header">
|
||||
<h1>zrok</h1>
|
||||
<Version/>
|
||||
<Logout user={user} logout={() => { setUser(null); }}/>
|
||||
<Identities user={user}/>
|
||||
<Logout user={user} logout={() => {
|
||||
setUser(null);
|
||||
}}/>
|
||||
</header>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default App;
|
||||
|
||||
|
16
ui/src/Identities.js
Normal file
16
ui/src/Identities.js
Normal file
@ -0,0 +1,16 @@
|
||||
import {useEffect} from "react";
|
||||
import * as metadata from './api/metadata';
|
||||
|
||||
const Identities = (props) => {
|
||||
useEffect(() => {
|
||||
metadata.listIdentities().then((resp) => { console.log(resp); })
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h3>Identities</h3>
|
||||
</div>
|
||||
)
|
||||
};
|
||||
|
||||
export default Identities;
|
@ -2,10 +2,33 @@ import React from 'react';
|
||||
import ReactDOM from 'react-dom/client';
|
||||
import './index.css';
|
||||
import App from './App';
|
||||
import * as gateway from "./api/gateway";
|
||||
|
||||
const root = ReactDOM.createRoot(document.getElementById('root'));
|
||||
root.render(
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
</React.StrictMode>
|
||||
);
|
||||
);
|
||||
|
||||
gateway.init({
|
||||
url: '/api/v1',
|
||||
getAuthorization
|
||||
});
|
||||
|
||||
function getAuthorization(security) {
|
||||
switch(security.id) {
|
||||
case 'key': return getApiKey();
|
||||
default: console.log('default');
|
||||
}
|
||||
}
|
||||
|
||||
function getApiKey() {
|
||||
const localUser = JSON.parse(localStorage.getItem("user"))
|
||||
if(localUser) {
|
||||
console.log('getApiKey', localUser.token)
|
||||
return Promise.resolve({ apiKey: localUser.token });
|
||||
} else {
|
||||
throw new Error("token not available");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user