Skip to content

Commit

Permalink
fix: more descriptions, cookie tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
jrea committed Jul 17, 2023
1 parent eea7ab9 commit a145947
Show file tree
Hide file tree
Showing 17 changed files with 454 additions and 68 deletions.
3 changes: 2 additions & 1 deletion packages/browser/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ describe('nile db', () => {
if (k === 'auth') {
expect(props).toEqual([
'constructor',
'createProvider',
'getSSOProviders',
'login',
'signUp',
'updateSSOProvider',
'updateProvider',
]);
}
if (k === 'users') {
Expand Down
32 changes: 23 additions & 9 deletions packages/react/src/SSO/BaseSSOForm.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import React from 'react';
import { useMutation } from '@tanstack/react-query';
import { UpdateSSOProviderRequest } from '@theniledev/browser';
import { UpdateProviderRequest } from '@theniledev/browser';

import SimpleForm from '../lib/SimpleForm';
import { useApi } from '../context';
import { Attribute, AttributeType } from '../lib/SimpleForm/types';

import { Props } from './types';
import { OktaProps } from './types';

export default function BaseSSOForm(props: Props & { providerName: string }) {
export default function BaseSSOForm(
props: OktaProps & { providerName: string }
) {
const api = useApi();
const { config, providerName, onSuccess, onError, allowEdit = true } = props;
const attributes = React.useMemo(() => {
Expand All @@ -26,14 +28,17 @@ export default function BaseSSOForm(props: Props & { providerName: string }) {
label: 'Config url',
type: AttributeType.Text,
defaultValue: config?.configUrl ?? '',
helpText:
'The URL of the .well-known/openid-configuration for the identity provider',
required: true,
disabled: !allowEdit,
},
{
name: 'redirectURI',
label: 'Redirect URI',
type: AttributeType.Text,
helpText: 'Where users should be redirected to upon login',
helpText:
'Where users should be redirected to after a successful login',
defaultValue: config?.redirectURI ?? '',
required: true,
disabled: !allowEdit,
Expand All @@ -44,7 +49,8 @@ export default function BaseSSOForm(props: Props & { providerName: string }) {
type: AttributeType.Text,
defaultValue: config?.emailDomains?.join(', ') ?? '',
required: true,
helpText: 'A comma seperated list of email domains to be used',
helpText:
'A comma seperated list of email domains (@yourDomain.com) to be used',
disabled: !allowEdit,
},
];
Expand All @@ -68,11 +74,19 @@ export default function BaseSSOForm(props: Props & { providerName: string }) {
]);

const mutation = useMutation(
(ssoRequest: UpdateSSOProviderRequest) => {
return api.auth.updateSSOProvider({
(ssoRequest: UpdateProviderRequest & { emailDomains: string }) => {
const payload = {
providerName: providerName.toLowerCase(),
updateSSOProviderRequest: ssoRequest,
});
updateProviderRequest: {
...ssoRequest,
emailDomains: ssoRequest.emailDomains.split(','),
},
};
if (config != null) {
return api.auth.updateProvider(payload);
} else {
return api.auth.createProvider(payload);
}
},
{
onSuccess,
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/SSO/Okta.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';

import BaseSSOForm from './BaseSSOForm';
import { Props } from './types';
import { OktaProps } from './types';

export default function Okta(props: Props) {
export default function Okta(props: OktaProps) {
return <BaseSSOForm {...props} providerName="Okta" />;
}
1 change: 1 addition & 0 deletions packages/react/src/SSO/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { default as Okta } from './Okta';
export { default } from './BaseSSOForm';
export * from './types';
6 changes: 3 additions & 3 deletions packages/react/src/SSO/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { GetSSOProvider200Response } from '@theniledev/browser';
import { GetSSOProviders200Response } from '@theniledev/browser';

export type Props = {
config?: GetSSOProvider200Response;
export type OktaProps = {
config?: GetSSOProviders200Response;
onSuccess?: (data: unknown, variables: unknown) => void;
onError?: (e: Error) => void;
allowEdit?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion packages/react/test/SSO/Okta.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('Okta', () => {
global.fetch = token;
const api = {
auth: {
updateSSOProvider: async () => jest.fn(),
createProvider: async () => jest.fn(),
},
} as unknown as Client;
render(
Expand Down
3 changes: 3 additions & 0 deletions packages/server/openapi/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
},
"put": {
"$ref": "../src/auth/providers/openapi/paths/updateProvider.json"
},
"post": {
"$ref": "../src/auth/providers/openapi/paths/createProvider.json"
}
}
},
Expand Down
247 changes: 246 additions & 1 deletion packages/server/openapi/spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,252 @@
],
"summary": "Update SSO provider",
"description": "Update SSO provider by name",
"operationId": "updateSSOProvider",
"operationId": "updateProvider",
"parameters": [
{
"name": "providerName",
"in": "path",
"required": true,
"schema": {
"type": "string"
}
}
],
"requestBody": {
"content": {
"*/*": {
"schema": {
"required": [
"clientId",
"clientSecret",
"configUrl",
"emailDomains",
"redirectURI"
],
"type": "object",
"properties": {
"configUrl": {
"type": "string",
"format": "uri"
},
"clientId": {
"type": "string"
},
"clientSecret": {
"type": "string"
},
"redirectURI": {
"type": "string",
"format": "uri"
},
"emailDomains": {
"type": "array",
"items": {
"type": "string"
}
},
"enabled": {
"type": "boolean"
}
}
}
}
},
"required": true
},
"responses": {
"200": {
"description": "Updated OIDC provider",
"content": {
"application/json": {
"schema": {
"required": [
"clientId",
"configUrl",
"provider",
"redirectURI",
"tenantId"
],
"type": "object",
"properties": {
"id": {
"type": "string",
"readOnly": true
},
"tenantId": {
"type": "string"
},
"provider": {
"type": "string"
},
"configUrl": {
"type": "string",
"format": "uri"
},
"clientId": {
"type": "string"
},
"redirectURI": {
"type": "string",
"format": "uri"
},
"emailDomains": {
"type": "array",
"items": {
"type": "string"
}
},
"enabled": {
"type": "boolean"
}
}
}
}
}
},
"400": {
"description": "OIDC provider name mismatch",
"content": {
"application/json": {
"schema": {
"required": [
"errorCode",
"message",
"statusCode"
],
"type": "object",
"additionalProperties": true,
"properties": {
"errorCode": {
"type": "string",
"enum": [
"internal_error",
"bad_request",
"entity_not_found",
"duplicate_entity",
"invalid_credentials",
"unknown_oidc_provider",
"provider_already_exists",
"provider_config_error",
"provider_mismatch",
"provider_update_error",
"session_state_missing",
"session_state_mismatch",
"oidc_code_missing"
],
"message": {
"type": "string"
},
"statusCode": {
"type": "integer",
"format": "int32"
}
}
}
}
}
}
},
"401": {
"description": "Unauthorized",
"content": {
"application/json": {
"schema": {
"required": [
"errorCode",
"message",
"statusCode"
],
"type": "object",
"additionalProperties": true,
"properties": {
"errorCode": {
"type": "string",
"enum": [
"internal_error",
"bad_request",
"entity_not_found",
"duplicate_entity",
"invalid_credentials",
"unknown_oidc_provider",
"provider_already_exists",
"provider_config_error",
"provider_mismatch",
"provider_update_error",
"session_state_missing",
"session_state_mismatch",
"oidc_code_missing"
],
"message": {
"type": "string"
},
"statusCode": {
"type": "integer",
"format": "int32"
}
}
}
}
}
}
},
"404": {
"description": "OIDC provider not found",
"content": {
"application/json": {
"schema": {
"required": [
"errorCode",
"message",
"statusCode"
],
"type": "object",
"additionalProperties": true,
"properties": {
"errorCode": {
"type": "string",
"enum": [
"internal_error",
"bad_request",
"entity_not_found",
"duplicate_entity",
"invalid_credentials",
"unknown_oidc_provider",
"provider_already_exists",
"provider_config_error",
"provider_mismatch",
"provider_update_error",
"session_state_missing",
"session_state_mismatch",
"oidc_code_missing"
],
"message": {
"type": "string"
},
"statusCode": {
"type": "integer",
"format": "int32"
}
}
}
}
}
}
}
},
"security": [
{
"jwtBearerAuth": []
}
]
},
"post": {
"tags": [
"authentication"
],
"summary": "Create SSO provider",
"description": "Create an SSO provider by name",
"operationId": "createProvider",
"parameters": [
{
"name": "providerName",
Expand Down
4 changes: 3 additions & 1 deletion packages/server/src/auth/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import Auth from './';
const baseConfig = [
'_tenantId',
'api',
'createProvider',
'database',
'workspace',
'db',
'getProviders',
'listProviders',
'listTenantProviders',
'login',
'loginSSO',
'loginSSOUrl',
Expand Down
Loading

0 comments on commit a145947

Please sign in to comment.