mirror of
https://github.com/openziti/zrok.git
synced 2025-01-11 00:18:43 +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 Login from './Login';
|
||||||
import Logout from './Logout';
|
import Logout from './Logout';
|
||||||
import Version from './Version';
|
import Version from './Version';
|
||||||
import * as gateway from "./api/gateway";
|
|
||||||
import {useEffect, useState} from "react";
|
import {useEffect, useState} from "react";
|
||||||
|
import Identities from "./Identities";
|
||||||
gateway.init({
|
|
||||||
url: '/api/v1'
|
|
||||||
});
|
|
||||||
|
|
||||||
const App = () => {
|
const App = () => {
|
||||||
const [user, setUser] = useState();
|
const [user, setUser] = useState();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const localUser = localStorage.getItem("user")
|
const localUser = localStorage.getItem("user")
|
||||||
if(localUser) {
|
if (localUser) {
|
||||||
setUser(JSON.parse(localUser))
|
setUser(JSON.parse(localUser))
|
||||||
console.log('reloaded user', localUser)
|
console.log('reloaded user', localUser)
|
||||||
}
|
}
|
||||||
@ -32,10 +28,14 @@ const App = () => {
|
|||||||
<header className="zrok-header">
|
<header className="zrok-header">
|
||||||
<h1>zrok</h1>
|
<h1>zrok</h1>
|
||||||
<Version/>
|
<Version/>
|
||||||
<Logout user={user} logout={() => { setUser(null); }}/>
|
<Identities user={user}/>
|
||||||
|
<Logout user={user} logout={() => {
|
||||||
|
setUser(null);
|
||||||
|
}}/>
|
||||||
</header>
|
</header>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default App;
|
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,6 +2,7 @@ import React from 'react';
|
|||||||
import ReactDOM from 'react-dom/client';
|
import ReactDOM from 'react-dom/client';
|
||||||
import './index.css';
|
import './index.css';
|
||||||
import App from './App';
|
import App from './App';
|
||||||
|
import * as gateway from "./api/gateway";
|
||||||
|
|
||||||
const root = ReactDOM.createRoot(document.getElementById('root'));
|
const root = ReactDOM.createRoot(document.getElementById('root'));
|
||||||
root.render(
|
root.render(
|
||||||
@ -9,3 +10,25 @@ root.render(
|
|||||||
<App />
|
<App />
|
||||||
</React.StrictMode>
|
</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