-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add authentication to the Web UI #3711
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
nodeLinker: node-modules | ||
|
||
yarnPath: .yarn/releases/yarn-4.1.1.cjs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { JSONSchema7 } from "json-schema"; | ||
import { ListRequest, ListResponse } from "./baseInterfaces"; | ||
|
||
// A request to list the authentication methods that the node supports. | ||
export interface ListAuthnMethodsRequest extends ListRequest { } | ||
|
||
// A response listing the authentication methods that the node supports. | ||
export interface ListAuthnMethodsResponse extends ListResponse { | ||
// The name of a method mapped to that method's requirements. | ||
// The name must be subsequently used to submit data. | ||
Methods: {[key: string]: Requirement} | ||
} | ||
|
||
// A requirement of an authn method, with the params varying per-type. | ||
export type Requirement = { | ||
type: "challenge" | ||
params: ChallengeRequirement | ||
} | { | ||
type: "ask" | ||
params: AskRequirement | ||
} | ||
|
||
// The "ask" type just gives the client a JSON Schema that describes the fields | ||
// it needs to collect from the user and submit. | ||
export type AskRequirement = JSONSchema7 | ||
|
||
// The "challenge" type gives the client an input phrase it must sign using its | ||
// private key. | ||
export interface ChallengeRequirement { | ||
InputPhrase: string | ||
} | ||
|
||
// A request to authenticate using a given method, including any credentials. | ||
export interface AuthnRequest { | ||
Name: string | ||
MethodData: AskRequest | ChallengeRequest | ||
} | ||
|
||
// The "ask" type needs the fields requested from the user by the JSON Schema. | ||
export type AskRequest = {[key: string]: string} | ||
|
||
// The "challenge" type needs the signature of the phrase and the associated | ||
// public key. | ||
export interface ChallengeRequest { | ||
PhraseSignature: string | ||
PublicKey: string | ||
} | ||
|
||
export interface AuthnResponse { | ||
Authentication: Authentication | ||
} | ||
|
||
// A response from trying to authenticate. | ||
export interface Authentication { | ||
// Whether the authentication was successful. | ||
success: boolean | ||
// Any additional info about why authentication was successful or not. | ||
reason?: string | ||
// The token the client should use in subsequent API requests. | ||
token?: string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// The interfaces in this file match those in base_requests.go | ||
|
||
export interface Request { | ||
namespace?: string | ||
} | ||
|
||
export interface GetRequest extends Request {} | ||
|
||
export interface ListRequest extends GetRequest { | ||
limit?: number | ||
next_token?: string | ||
order_by?: string | ||
reverse?: boolean | ||
} | ||
|
||
export interface ListResponse { | ||
NextToken: string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
form { | ||
display: grid; | ||
grid-template-columns: 4fr 6fr; | ||
row-gap: 1em; | ||
column-gap: 1em; | ||
|
||
h3 { | ||
margin: 0; | ||
grid-column: span 2; | ||
} | ||
|
||
label { | ||
text-transform: capitalize; | ||
} | ||
|
||
label[data-required=true]::after { | ||
content: "*"; | ||
color: red; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import React from "react"; | ||
import { JSONSchema7, JSONSchema7Definition } from "json-schema"; | ||
import { AskRequest, AskRequirement, AuthnRequest } from "../../helpers/authInterfaces"; | ||
import "./AskInput.module.scss" | ||
|
||
interface AskInputProps { | ||
name: string | ||
requirement: AskRequirement | ||
authenticate: (req: AuthnRequest) => void | ||
cancel: () => void | ||
} | ||
|
||
function propertyToInputType(property: JSONSchema7Definition): React.HTMLInputTypeAttribute { | ||
if (typeof property === "boolean") { | ||
return "text" | ||
} | ||
|
||
if (property.writeOnly) { | ||
return "password" | ||
} | ||
|
||
switch (property.type) { | ||
case "number": | ||
case "integer": | ||
return "number" | ||
case "boolean": | ||
return "checkbox" | ||
default: | ||
return "text" | ||
} | ||
} | ||
|
||
export const AskInput: React.FC<AskInputProps> = (props: AskInputProps) => { | ||
const requirement = props.requirement | ||
const properties = requirement.properties ?? {} | ||
const fields = Object.keys(properties) | ||
const required = requirement.required ?? [] | ||
|
||
// Sort by fields listed in required order | ||
fields.sort((a, b) => required.indexOf(a) - required.indexOf(b)) | ||
|
||
const inputs = fields.map(field => { | ||
const property = properties[field] as JSONSchema7 | ||
return <> | ||
<label htmlFor={field} data-required={required.includes(field)}> | ||
{field} | ||
</label> | ||
<input | ||
name={field} | ||
type={propertyToInputType(property)} | ||
required={required.includes(field)} /> | ||
</> | ||
}) | ||
|
||
const submit: React.FormEventHandler<HTMLFormElement> = (event) => { | ||
event.preventDefault() | ||
|
||
const formData = new FormData(event.currentTarget) | ||
const objectData: AskRequest = {} | ||
formData.forEach((value, key) => {objectData[key] = value.toString()}) | ||
|
||
const request: AuthnRequest = {Name: props.name, MethodData: objectData} | ||
props.authenticate(request) | ||
|
||
return false | ||
} | ||
|
||
return <form onSubmit={submit} onReset={props.cancel}> | ||
<h3>Authenticate using {props.name.replaceAll(/[^A-Za-z0-9]/g, ' ')}</h3> | ||
{...inputs} | ||
<input type="reset" value="Cancel"/> | ||
<input type="submit" value="Authenticate"/> | ||
</form> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
@import "../../styles/container"; | ||
@import "../../styles/button"; | ||
@import "../../styles/variables"; | ||
|
||
.flow { | ||
@include container; | ||
width: 50%; | ||
margin-left: auto; | ||
margin-right: auto; | ||
min-width: 250px; | ||
|
||
button, input[type=submit], input[type=reset] { | ||
@include button; | ||
} | ||
|
||
input[type=reset] { | ||
background-color: $grey-label; | ||
color: $grey-text; | ||
|
||
&:hover { | ||
background-color: rgba($grey-label, 0.7); | ||
} | ||
|
||
&:active { | ||
background-color: rgba($grey-label, 0.8); | ||
} | ||
} | ||
|
||
h3 { | ||
margin: 0; | ||
} | ||
|
||
ul { | ||
list-style: none; | ||
padding: 0; | ||
|
||
li { | ||
margin-bottom: 1em; | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why did we need to remove this? I don't have a problem with the change - just curious
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's added at https://github.com/bacalhau-project/bacalhau/pull/3711/files#diff-19907c38cadb733516c5d0d2d452e8ef1dde593253b301251fec43f1a8a8d315 instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
134db3f