Skip to content
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

Subscription key improvements #2212

Merged
merged 1 commit into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ <h3 class="pt-0">
<div class="row flex flex-row">
<div class="col-4">
<label for="authServer" class="text-monospace form-label"
data-bind="text: $component.authorizationServer().displayName"></label>
data-bind="text: $component.authorizationServer().displayName"></label>
</div>
<div class="col-7">
<div class="form-group">
<select id="authServer" class="form-control"
data-bind="options: $component.authorizationServer().grantTypes, value: $component.selectedGrantType, optionsCaption: 'No auth'">
data-bind="options: $component.authorizationServer().grantTypes, value: $component.selectedGrantType, optionsCaption: 'No auth'">
</select>
</div>
</div>
Expand Down Expand Up @@ -49,7 +49,7 @@ <h3 class="pt-0">
<div class="col-7">
<div class="form-group">
<button class="button button-primary"
data-bind="click: $component.authenticateOAuthWithPassword">Authorize</button>
data-bind="click: $component.authenticateOAuthWithPassword">Authorize</button>
</div>
</div>
</div>
Expand Down Expand Up @@ -79,8 +79,15 @@ <h3 class="pt-0">
</select>
<!-- /ko -->
<!-- ko if: !$component.products() || $component.products().length === 0 -->
<input id="subscriptionKey" type="text" class="form-control" placeholder="subscription key"
data-bind="textInput: $component.selectedSubscriptionKey" />
<div class="input-group">
<input id="subscriptionKey" class="form-control" placeholder="subscription key"
data-bind="textInput: $component.selectedSubscriptionKey, attr: { type: subscriptionKeyRevealed() ? 'text' : 'password' }"
aria-required="true" />
<button data-bind="click: toggleSubscriptionKey" class="input-group-addon">
<i
data-bind="class: subscriptionKeyRevealed() ? 'icon-emb icon-emb-eye-fill' :'icon-emb icon-emb-eye'"></i>
</button>
</div>
<!-- /ko -->
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export class Authorization {
public readonly authorizationError: ko.Observable<string>;
public readonly products: ko.Observable<Product[]>;
public readonly selectedSubscriptionKey: ko.Observable<string>;
public readonly subscriptionKeyRevealed: ko.Observable<boolean>;
private deleteAuthorizationHeader: boolean = false;

constructor(
Expand All @@ -58,6 +59,7 @@ export class Authorization {
this.authorizationError = ko.observable();
this.products = ko.observable();
this.selectedSubscriptionKey = ko.observable();
this.subscriptionKeyRevealed = ko.observable(false);
}

@Param()
Expand Down Expand Up @@ -89,6 +91,18 @@ export class Authorization {
if (this.api().subscriptionRequired) {
await this.loadSubscriptionKeys();
}

if (this.subscriptionKeyRequired()) {
if (this.api().type === TypeOfApi.webSocket || this.isGraphQL()) {
this.setSubscriptionKeyParameter();
} else {
this.setSubscriptionKeyHeader();
}
}
}

public toggleSubscriptionKey(): void {
this.subscriptionKeyRevealed(!this.subscriptionKeyRevealed());
}

private isGraphQL(): boolean {
Expand Down Expand Up @@ -184,13 +198,8 @@ export class Authorization {
return this.findHeader(KnownHttpHeaders.Authorization);
}

private setSubscriptionKeyHeader(subscriptionKey: string): void {
private setSubscriptionKeyHeader(subscriptionKey?: string): void {
this.removeSubscriptionKeyHeader();

if (!subscriptionKey) {
return;
}

const subscriptionKeyHeaderName = this.getSubscriptionKeyHeaderName();

const keyHeader = new ConsoleHeader();
Expand Down Expand Up @@ -401,24 +410,20 @@ export class Authorization {
}
}

private setSubscriptionKeyParameter(subscriptionKey: string): void {
private setSubscriptionKeyParameter(subscriptionKey?: string): void {
const subscriptionKeyParam = this.getSubscriptionKeyParam();
this.removeQueryParameter(subscriptionKeyParam);

if (!subscriptionKey) {
return;
}

const subscriptionKeyParamName = this.getSubscriptionKeyParamName();

const keyParameter = new ConsoleParameter();
keyParameter.name(subscriptionKeyParamName);
keyParameter.value(subscriptionKey);
keyParameter.secret = true;
keyParameter.type = "string";
keyParameter.canRename = false;
keyParameter.required = true;
keyParameter.inputType("password");
keyParameter.value.extend(<any>{ required: { message: `Value is required.` } });
keyParameter.value(subscriptionKey);

if (this.isGraphQL()) {
this.queryParameters.push(keyParameter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ <h3 class="pt-0">
<input type="text" autocomplete="off" class="form-control form-control-sm"
placeholder="name" spellcheck="false" aria-label="Parameter name"
data-bind="textInput: parameter.name, attr:{ 'readonly': parameter.required }">
<span class="invalid-feedback" data-bind="validationMessage: parameter.name"></span>
<span class="invalid-feedback"
data-bind="validationMessage: parameter.name"></span>
</div>
</div>
</div>
Expand All @@ -68,15 +69,17 @@ <h3 class="pt-0">
data-bind="textInput: parameter.value, attr:{ 'aria-required': parameter.required }">
<!-- /ko -->
<!-- ko if: parameter.secret-->
<input autocomplete="off" class="form-control form-control-sm" placeholder="value"
spellcheck="false" aria-label="Parameter value"
<input autocomplete="off" class="form-control form-control-sm"
placeholder="value" spellcheck="false" aria-label="Parameter value"
data-bind=" attr: {type: parameter.inputType, 'aria-required': parameter.required }, textInput: parameter.value">
<button data-bind="click: () => $component.toggleSecretParameter(parameter)"
class="input-group-addon">
<i
data-bind="class: parameter.revealed() ? 'icon-emb icon-emb-eye-fill' :'icon-emb icon-emb-eye'"></i>
</button>
<!-- /ko -->
<span class="invalid-feedback"
data-bind="validationMessage: parameter.value"></span>
<!-- /ko -->
</div>
</div>
Expand Down Expand Up @@ -115,7 +118,8 @@ <h3 class="pt-0">
<input type="text" autocomplete="off" class="form-control form-control-sm"
placeholder="name" spellcheck="false" aria-label="Header name"
data-bind="textInput: header.name, attr: { 'readonly': header.required }">
<span class="invalid-feedback" data-bind="validationMessage: header.name"></span>
<span class="invalid-feedback"
data-bind="validationMessage: header.name"></span>
</div>
</div>
</div>
Expand All @@ -130,7 +134,8 @@ <h3 class="pt-0">
<input type="text" autocomplete="off" class="form-control form-control-sm"
placeholder="value" spellcheck="false" aria-label="Header value"
data-bind="textInput: header.value, attr: { 'aria-required': header.required }">
<span class="invalid-feedback" data-bind="validationMessage: header.value"></span>
<span class="invalid-feedback"
data-bind="validationMessage: header.value"></span>
</div>
<!-- /ko -->
</div>
Expand Down Expand Up @@ -199,11 +204,11 @@ <h4 class="mt-30">
<div class="flex flex-column align-items-end">

<!-- ko if: hasErrorEditors() -->
<div class="panel panel-dark animation-fade-in gql-editor-errors"
<div class="alert alert-danger animation-fade-in gql-editor-errors"
data-bind="scrollintoview: {}">
<p>Unable to send the request</p>
<!-- ko foreach: { data: editorErrors, as: 'error' } -->
<p class="text-muted mb-unset" data-bind="html: error"></p>
<p data-bind="html: error"></p>
<!-- /ko -->
</div>
<!-- /ko -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ export class GraphqlConsole {
this.wsProcessing = ko.observable(false);
this.displayWsConsole = ko.observable(false);
this.wsLogItems = ko.observableArray([]);

validation.registerExtenders();

validation.init({
insertMessages: false,
errorElementClass: "is-invalid",
decorateInputElement: true
});
}

@Param()
Expand Down Expand Up @@ -286,12 +294,14 @@ export class GraphqlConsole {

public async validateAndSendRequest(): Promise<void> {
const headers = this.headers();
const parameters = [].concat(headers);
const queryParameters = this.queryParameters();
const parameters = [].concat(headers, queryParameters);
const validationGroup = validation.group(parameters.map(x => x.value), { live: true });
const clientErrors = validationGroup();

if (clientErrors.length > 0) {
validationGroup.showAllMessages();
this.editorErrors.push("Required fields are missing or incomplete. Please review the request and ensure all required information is provided. Look for highlighted areas with error indicators.");
return;
}

Expand Down
Loading