Commit Graph

37 Commits

Author SHA1 Message Date
Aswin V 2e5da524cf
Enhancements (#584)
* Throw error if `entityID` is missing

* Use `JacksonError` instead of Error

* Type enhancements - use `SAMLSSORecord`

* Better typing with `OIDCSSORecord`

* Add types for response

* Update swagger

* Sync package lock

* Assert connection record type in tests

* Mark `@deprecated` for config methods

* Mark `openid` as optional

* Gaurd against nullish

* Fix test

* Add entityID check for update op, add tests

* Cleanup `t.end()`, not required for `async` tests

* Remove oidcPath check in defaultOpts

* Return error if `oidcPath` is empty in authorize for OIDC Connection

* Add missing `async`

* Fail connection add/update if `oidcPath` is not set

* Type alignment

* Update swagger spec

* Fix type for `oidcPath`

* Cleanup

* Add missing return types and fix type for `getConfig`

* Bump up version

* Update swagger spec

* Remove uffizzi from ignore file

Co-authored-by: Kiran <kiran@boxyhq.com>
2022-10-11 20:32:18 +05:30
Aswin V d5cbb40d91
Support for OIDC Identity Providers (#385)
* Support connection dynamic param in route

* Pass `connection`

* Fix tests

* Accept oidc params and validate the same

* Rename `connection` --> `strategy`

* Use saml for preLoadedConfig for now

* Rename `apiController` --> `apiConfigController`

* Flatten the params

* Validate passed config

* Backward compatibility for embed setup

* Impl for oidc config save

* index addition for oidc clientId

* Remove param, defaults to saml

* Validation will be done inside controller

* Zap secondary index on clientId, not required

* Rename `APIConfigController` --> `ConfigAPIController`

* Update swagger

* Fix name

* Fix name elsewhere

* Revert filter

* Split `saml` and `oidc` create/update logic

* Route `saml` and `oidc`

* Test update

* Update swagger

* Update swagger

* Use tenant/product from stored config
in lieu of params

* Validate passed OIDC clientId using hash

* Update swagger annotations

* Handlers for getting OIDC/SAML configs

* Validate tenant/product in update

* Typo fix

* Fix test

* Default to empty string, validation is done
to check if the params are not empty

* Extract provider name just like saml

* OIDC Connection support
*delta for authorize*
- Renamed samlConfig(s) → connection(s)
- Renamed resolvedSamlConfig -> resolvedConnection
- Detect connection is SAML or OIDC
- Perform Issuer discovery and oidc client init
- Tweak error responses
- Persist oidc client metadata in session

* Test type fix

* Test fix

* openid-client dependency

* Sync package locks

* Fix return type
- Remove `undefined` from return type
- Return `OAuthErrorResponse` for else case

* Handle OIDC Authorization response

* Persist OIDC code_verifier

* Remove scope check for OIDC connection

* Normalize scope before relaying

* Method name update

* Extract user profile from id token and userinfo

* Handle error response from OIDC Provider

* Update type

* Type update with OIDC specific error codes

* Bug fix : typo

* Cleanup

* OIDC callback route

* Bug fix: return profile and parameter fix

* Rename `config` -> `connection`

* Use `Link` and add oidc connection nav item

* Use `strategy` from query param

* Delta ↴
 - Reorganised api routes
 - Removed Admin controller filtering methods for saml/oidc

* Fix page link in e2e test

* Changes:
 - Handle oidc connection fields
 - Rename component file path

* Remove slug for save/update connection

* Fix keyname in update operation

* Import path update

* Radio select connection type for new connection

* Update lock file

* Sync lock file

* Sync package lock

* Fix connectionType detection for new connection

* Fix error message

* Add comment

* Tweak comment

* Use the correct state and directly from session

* Sync lock file

* Remove `provider` from OAuthReqBody

* Remove duplicate scopes

* Pass recent param additions to idpSelection page

* Add badge for Provider type

* Style tweak

* Style IdP type selection

* Add test for oidc provider

* Comment

* Check for empty state

* Add test for oidcAuthzResponse

* Add test for oidcAuthzResponse

* Add test for error response from OP

* Error message tweak

* Test the happy path

* Remove unused import

* Fix assertion

* - Fix types
- add createOIDCConfig` test for missing params

* Test happy path for `createOIDCConfig`

* Param validation tests for `createOIDCConfig`

* Test for `updateOIDCConfig`

* Tests for `updateOIDCConfig`

* Male `oidcPath` required like `samlPath`

* Bump `openid-client` version

* Refactor

* Update test coverage map

* Tweak label

* Split openid/oauth tests

* call `t.end`

* Fix file name in comment

* Add test teardown

* Improve coverage and rename test files

* For backwards compatibility

* Minor formatting

* Add api paths for /connection

* Zap config path for admin ui

* Update swagger spec

* Rename `configAPIController`
→ `connectionAPIController`

* Rename `IdPConfig` → `IdPConnection`

* Rename `validateIdPConfig` → `validateIdPConnection`

* Rename `createSAMLConfig` → `createSAMLConnection`

* Rename `createOIDCConfig` → `createOIDCConnection`

* Update swagger spec

* Rename `updateSAMLConfig` → `updateSAMLConnection`,
 `updateOIDCConfig` → `updateOIDCConnection`

* Make `clientID`/`clientSecret` readOnly

* Rename `configStore` → `connectionStore`

* Update swagger spec

* Add `getConnection` + `deleteConnection`

* Remove `/api/v1/oidc/config`
and keep `api/v1/saml/config`

* Rename `getAllConfig` → `getAllConnection`

* Rename `readConfig` → `loadConnection`

* Rename `deleteConfiguration` → `deleteConnection`

* Add `preLoadedConnection` env

* Update map and cli

* Refactor api tests and rename config to connection

* Rename `configList` → `connectionList`

* Rename `samlConfig` → `samlConnection`

* Rename config -> connection

* Rename `config` → `connection`

* Rename counters for otl

* Sync package lock

* Remove api key validation from api route

* Update Admin ui title

* Update swagger

* Update otl metric descriptions

* Update var naming to connection

* Add strategy validation

* Add tests for invalid strategy

* Sync package lock

* Upgrade and pin version

* Update saml config api with deprecated

* Updated swagger spec for deprecated config api

* Bump package version

* Fix label

* - removed strategy for `get` and `delete`
 - Type update

* Type updates

* getConnection -> getConnections,
deleteConnection -> deleteConnections

* Update swagger spec

* Use only for saml connection

* Remove slug from api routes

* API path updates

* Type updates

* Helper util for api routes to check strategy

* Type updates and api changes

* `OAuthReq` typings enhancement

* Narrowed down types for `OAuthTokenReq` and
`OIDCAuthzResponsePayload`

* `IdPConnection` -> `SSOConnection`

* Update cookie name to avoid clash

* Handle the uncaught case to prevent req hanging
2022-09-30 11:37:21 +01:00
Utkarsh Mehta b8ca1f38a4
Tenant product validation (#555)
* comments

* added validation & tests
2022-09-27 17:49:57 +01:00
Utkarsh Mehta 402dad5215
Support forceAuthn (#530)
* Support ForceAuthn added

* forceAuthn override on the back of the OAuth 2.0

* added tests and minor fixes for forceAuthn

* Override ForceAuthn tests

* chnages in the override flag and using prompt

* using node forge for self signed certs

* Revert "using node forge for self signed certs"

This reverts commit c027b5b7ce.
2022-09-27 17:49:27 +01:00
Deepak Prabhakara 3470632c80 fixed typos 2022-09-21 18:25:06 +01:00
Utkarsh Mehta f1f3daa823
Self signed certificate expiry issue (#508)
* certificate expiry date

* fixed the expiry date

* checking the cert expiry and regenerating them

* removed console log
2022-09-21 22:51:11 +05:30
Aswin V 32cb2c5189
Forward the recent param additions to IdP selection page (#451)
Forward the recent param additions to selection
page
2022-08-23 13:59:36 +05:30
Aswin V fcebf012a6
Fix IdP initiated saml login (#423)
* handle IdP flow where `requested` is `undefined`

* Add test for IdP flow

* Optional chaining for `requested.redirect_uri`
2022-08-15 11:59:51 +05:30
Aswin V da1b7b8423
Validate redirect_uri in code exchange (#412)
* Add `redirect_uri` to `requested` in session

* Check if the `redirect_uri` matches from
original request

* Typing and test updates
2022-08-12 17:20:05 +05:30
Deepak Prabhakara d63b949ec1
fixed default value for jwsAlg (#397) 2022-08-01 13:57:03 +01:00
Deepak Prabhakara 6c1981e855
Support encoded tenant and product in the resource OAuth param (#386) 2022-07-27 21:53:37 +01:00
Aswin V 9b23eed3e3
Support for OIDC flow (#306)
* Support 'POST' at authorization endpoint

* handle additional scope params

* handle additional claims param

* Try with `legacy-peer-deps` true

* Fix logic

* Set legacy-peer-deps to `true`

* Remove `.npmrc` files and sync packages from main

* Resolve conflicts

* Load jwtSigningKeys into env

* Return id_token for OIDC flow

* Support `nonce`

* Add type for `nonce`

* Set `nonce` only if present in request

* Expose OpenId provider metadata

* Update metadata

* Tweak path remove dot, map jwks

* Add jwsAlg and source keys using base64

* Source jose from root package.json too

* JWS utils

* Serve jwks_uri

* Load private key for signing

* Fix authz endpoint

* Format example env

* Fix claims

* Format discovery and add missing metadata

* Include the basic profile in id_token

* Fix claims access

* Remove console log

* Sync package lock

* Cleanup

* Support for claims is optional

* cleanup type

* Set `Content-Type` header

* Remove default from env

* Handle jwt env

* oidc fixture

* Test for oidc flow, check id_token in response

* Add jwt envs

* Fix for undefined

* Remove keys check in controller init

* Runtime check for JWS keys

* check if id_token is absent

* Check for claims and verify signature

* Snapshot test oidc discovery page

* Add snapshot for linux to work in CI

* Test with a fontless screenshot

* test with this one

* add a debug step

* Get the entire dir for snapshot

* Test with this

* Comment out debug step

* snapshot test jwks

* Update env

* Upload screenshot for linux

* Add debug step

* Update snapshot

* Sync package lock

* Remove local testing snapshots

* Assert using api request

* Update to use api test for jwks endpoint

* Set `JWS_ALG` env

* Prefix openid vars

* Fix env access

* Fix e2e test

* Fix options in tests

* Fix env var access

* Use ttl from env

* Simplify exp value setting

* oidc discovery controller

* Fix typing

* Handle case where signing keys are not set

* return `oidcDiscoveryController`

* Throw a JacksonError like object

* Use controllers and cleanup

* throw JacksonError like object

* Minor formatting

* Fix typing and add check for undefined

* Keep order of packages same as in main

* Update key generation comment

* Initialise `openid` correctly in npm

* Cleanup

* Set `sub` claim

* Set 'sub' only for oidc flow
2022-07-23 18:04:55 +01:00
Aswin V bcf7c9ee14
Include state in OAuth error response (#344)
* Sync package lock

* Add state to the query params

* Include `state` in type

* Pass state from original request

* Add `state` to failing tests
2022-07-06 08:42:43 +05:30
vishalboxyhq 16b793a312
saml20 updates parseIssuer,validate and privatekey (#256)
* saml20 updates parseIssuer,validate and privatekey

* update test case for validte

* remove v in dependency version

* updated package.json

Co-authored-by: Deepak Prabhakara <deepak@boxyhq.com>
2022-05-31 21:37:16 +01:00
Aswin V e5fd1e9c89
Read encoded tenant product from scope (#209)
* Read encoded tenant product from scope

* Remove redundant check

* Generic naming

* Fix test missing client_id

* Add test for scope
2022-05-17 11:13:29 +01:00
Aswin V aa25d14791
OAuth 2.0 Error handling (#198)
* helper utils for OAuthErrorResponse

* Return back to redirect_uri with error and desc

* return OAuthError inside samlResponse for SP flow

* Fix test

* Remove punctuation

* Add new tests

* Add test for absent binding in config

* Add test for samlResponse OAuth error

* Test for OAuth error in saml request
creation failure

* Rename mock metadata to fixture

* Refactor

* Refactor fixture

* Update comment

* Update type for `Profile`

* Add fixture for token_req

* Assert for requested in userinfo

* Refactor body for tokenReq to fixture

* Sync package lock

* Return error response for SP/IdP flow - IdP flow
can use the defaultRedirectUrl
2022-05-16 17:16:30 +05:30
Deepak Prabhakara 6c7eae91f1
set requested tenant and product when using client_id (#199) 2022-05-10 12:17:57 +01:00
Aswin V a85a72e6c2
Support access_type query param for tenant/product selection (#187)
* Sync package lock

* Rename function

* Accept tenant/product in access_type param

* Change const to let

* Add test for access_type param
2022-05-05 19:00:39 +01:00
Aswin V 7ae34e47d1
Support multiple config matches for a single tenant/product (#149)
* IdP selection page

* Add idpDiscoveryPath option

* Generalise redirection logic

* Handle redirect_to_idp_select

* Support for array value [idpList]

* Implement redirection to IdP selection page

* remove redirect_to_idp_select

* Filter our undefined values

* Remove returnTo

* Check if idpDiscovery is enabled

* Cleanup

* Basic layout plus styling

* Add idpDiscoveryPath to env

* Package lock changes

* Simplify empty handling

* Rename to idp_hint

* refactor

* Pass along idp_hint in requested

* Switch from form to link

* Check and set requested

* Tenant/product should be optional

* Fix condition

* App selection for IdP flow

* cleanup

* Pin version

* updated to saml20 v1.0.1

* Latest lock file

* Use generic createPostForm from saml20

* Style alignment

* Style name and description

Co-authored-by: Deepak Prabhakara <deepak@boxyhq.com>
2022-04-29 16:51:03 +01:00
Deepak Prabhakara c276e874aa
Move saml related functionality to saml20-maintained (#144)
* Moved saml into saml20-maintain

* fixed import

* added test script

* use * import to standardise

* crash fix

* fixed sinon mocking in tests

* use createPostForm from saml20

* signout -> logout

* updated saml20 to the beta version

* tweaks

* use saml.sign

* switch completely to saml20

* removed duplicate prettier config file

* updated saml20

Co-authored-by: Vishal Lodha <vishal@boxyhq.com>
2022-04-26 18:01:55 +01:00
Deepak Prabhakara 9601179e4d
Fixed multiple configs match (same entityID) (#143)
* fixed issue where the same entityID matches different tenant and product combination. Very common with providers (example Auth0)

* bumped up version

* only filter if there are more than 1 saml config
2022-04-05 21:28:12 +01:00
Aswin V 1e44163f90
Check client_secret if client_id is dummy (#140)
* check client_secret if client_id is dummy

* Add test for client_secret validation

* Also allow the secret linked to the config

* Use && instead of ||

* Add test for actual clientId/Secret

* Add test for clientId/secret happy path
2022-03-31 20:22:59 +01:00
Kiran K 39d1309cdd
SLO flow (#128)
* SLO flow

* Add request sign

* Validate the RelayState

* Response validate - Need fix

* Methods reorder

* Add Next.js route

* Remove the default value for samlAudience

* Add Next.js routes

* Add routes for Next.js and fixed the redirect issues

* Remove the old slo.ts

* Support HTTP-POST binding

* Add method to validate signature

* Revert - Make the samlAudience optional

* Fix the type issue, add a few unit tests

* Add unit tests

* Update the sample logout response XML

* Code cleanup

Co-authored-by: Deepak Prabhakara <deepak@boxyhq.com>
2022-03-30 11:52:04 +01:00
Deepak Prabhakara 130fb92cfc fixed crash during IdP login 2022-03-20 02:41:29 +00:00
Kiran K 8957f692c1
Send requested tenant, product in the userinfo profile (#123)
* Fixes #113

* Rename the variables, don't expand the requested params

Co-authored-by: Deepak Prabhakara <deepak@boxyhq.com>
2022-03-16 20:50:54 +00:00
Deepak Prabhakara bd1a68a8cc don't delete token after use, there are scenarios where user profile might have to be fetched twice 2022-03-16 18:00:56 +00:00
Deepak Prabhakara 7fb4357ce2
Delete token after use (#102)
* delete token after use

* delete session after use
2022-03-10 22:38:06 +00:00
Deepak Prabhakara ce1a9e9dfd
added x509data to AuthnRequest (#97)
* added x509data to AuthnRequest

* TS fix

* TS fix

* workflows cleanup
2022-02-19 22:08:11 +00:00
Kiran K b03f1de4d4
Add support for HTTP-POST binding (#82)
* Add support for http-post

* send authorize_form as html

* package lock update

* fixed POST for Azure

* tweak

* Fix the unit test

* This seems like a better fix

* redirectUrl/authorizeForm can be undefined

Co-authored-by: Deepak Prabhakara <deepak@boxyhq.com>
2022-02-17 19:02:03 +00:00
Kiran K 78782fbbb8
Opentelemetry metrics API (#72)
* Opentelemetry metrics API

* Rename the counter

* Add metrics API

* Add Otl to Nextjs

* Add otel protocol

* Fix the port

* Fix the port

* Fix

* Fix

* Fix

* fixed default postgres url

* tweaks to metrics name and attributes

Co-authored-by: Kiran K <kiran@Kirans-MacBook-Pro.local>
Co-authored-by: Deepak Prabhakara <deepak@boxyhq.com>
2022-02-15 23:34:12 +00:00
Deepak Prabhakara 393322b147
added CLIENT_SECRET_VERIFIER for enhancing OAuth 2.0 security (#84)
* added CLIENT_SECRET_VERIFIER for enhancing OAuth 2.0 security when not using PKCE flow

* added CLIENT_SECRET_VERIFIER to env.example

* fixed unit test
2022-02-15 14:09:56 +00:00
Deepak Prabhakara 53ea631bcc allow tenant and product to be encoded inside client_id 2022-02-13 23:44:45 +00:00
Deepak Prabhakara 87bba57aaf comment tweak 2022-02-12 22:39:11 +00:00
Deepak Prabhakara aacc139c01 - RFC requires the saml request to be deflated before base64 encoding
- handle invalid token in userinfo
2022-01-20 21:05:23 +00:00
Kiran K 8c83cb76c9
Generate swagger spec (#68)
* Add Swagger - wip

* Add OpenAPI Spec

* Add OpenAPI Spec

* APi Doc

* Add the api paths

* Add auth block

* Moved into swagger 2.0

* Fix the Swagger spec

* Revert the changes to middleware

* Remove the sample files

* Add jsdoc

* Add swagger spec

* Remove the package pako

* Pin the version

* Pin the version

Co-authored-by: Deepak Prabhakara <deepak@boxyhq.com>
2022-01-19 00:13:18 +00:00
Deepak Prabhakara 9d43298597
check for code_verifier first (#59) 2022-01-08 00:59:48 +00:00
Deepak Prabhakara 3754f2b13d
Next.js service (#53)
* moved jackson-next to this repo

* fixed working-directory

* updated package-lock

* fixed docker build

* fixed dockerfile

* cleanup

* save npm version for use in the build step

* switching the order

* fixed env secret

* update saml-jackson to the current version before building the next.js service

* build from typescript and change main and types before publishing npm

* copy README.md from root before publishing npm

* update README only for prod versions

* read version from root package.json file

* fixed artifact

* updated package-lock
2022-01-05 12:09:51 +00:00
Renamed from src/controller/oauth.ts (Browse further)