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

feat(core): Add SAML post and test endpoints #5595

Merged

Conversation

flipswitchingmonkey
Copy link
Contributor

Github issue / Community forum post (link here to close automatically):

@flipswitchingmonkey flipswitchingmonkey changed the base branch from master to pay-156-change-user-update-endpoint March 2, 2023 08:16
@n8n-assistant n8n-assistant bot added core Enhancement outside /nodes-base and /editor-ui n8n team Authored by the n8n team labels Mar 2, 2023
@flipswitchingmonkey flipswitchingmonkey changed the title Pay 153 create internal api endpoints to set up feat(core): Add SAML post and test endpoints Mar 2, 2023
@flipswitchingmonkey flipswitchingmonkey marked this pull request as ready for review March 2, 2023 10:24
Copy link
Contributor

@RicardoE105 RicardoE105 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Just left some minor comments.

*/
samlControllerProtected.post(
SamlUrls.config,
samlLicensedOwnerMiddleware,
async (req: SamlConfiguration.Update, res: express.Response) => {
if (isSamlPreferences(req.body)) {
const validationResult = await validate(req.body);
if (validationResult.length === 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to return early?

if (!validationResult) throw new BadRequestError(...)

const result = await SamlService.getInstance().setSamlPreferences(req.body);
			return res.send(result);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, validationresult is supposed to be empty (validate() returns an array with the number of errors it found, so ideally length=0)

SamlUrls.configToggleEnabled,
samlLicensedOwnerMiddleware,
async (req: SamlConfiguration.Toggle, res: express.Response) => {
if (req.body.loginEnabled !== undefined) {
Copy link
Contributor

@RicardoE105 RicardoE105 Mar 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const { loginEnabled } = req.body;

if (loginEnabled === undefined ) 		throw new BadRequestError('....')

await SamlService.getInstance().setSamlPreferences({ loginEnabled: req.body.loginEnabled });

res.sendStatus(200);

if (result?.binding === 'redirect') {
// forced client side redirect
return res.send(getInitSSOPostView(result.context));
// return res.status(301).send(result.context.context);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove comment

samlControllerProtected.get(
SamlUrls.configTest,
async (req: express.Request, res: express.Response) => {
const testResult = await SamlService.getInstance().testSamlConnection();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we handle the case when the testing connection fails? That way, we can let the front end know that there might be an issue with the settings.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this is just a very basic implementation for the moment, until I know how the frontend wants to call it. Right now it's a return of true/false for the test, rather than an exception. The entire test process may change, since it may be better to have the owner go through a full sso flow instead to confirm it is working.

@@ -53,7 +61,7 @@ export class SamlService {
}

constructor() {
this.loadSamlPreferences()
this.loadFromDbAndApplySamlPreferences()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it not enough to call loadFromDbAndApplySamlPreferences only in the init method?

Base automatically changed from pay-156-change-user-update-endpoint to master March 3, 2023 09:05
@flipswitchingmonkey
Copy link
Contributor Author

i'll make the small changes as part of #5600 which already had many of them...

@flipswitchingmonkey flipswitchingmonkey merged commit 523fa71 into master Mar 3, 2023
@flipswitchingmonkey flipswitchingmonkey deleted the pay-153-create-internal-api-endpoints-to-set-up branch March 3, 2023 09:19
@n8n-assistant n8n-assistant bot added the Upcoming Release Will be part of the upcoming release label Mar 3, 2023
@janober
Copy link
Member

janober commented Mar 10, 2023

Got released with n8n@0.219.1

@janober janober removed the Upcoming Release Will be part of the upcoming release label Mar 10, 2023
sunilrr pushed a commit to fl-g6/qp-n8n that referenced this pull request Apr 24, 2023
* consolidate SSO settings

* update saml settings

* fix type error

* limit user changes when saml is enabled

* add test

* add toggle endpoint and fetch metadata

* rename enabled param

* add handling of POST saml login request

* add config test endpoint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Enhancement outside /nodes-base and /editor-ui n8n team Authored by the n8n team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants