ordercloud-api / headstart-nextjs

A starter application built using NextJS and OrderCloud
https://headstart-nextjs-mocha.vercel.app
16 stars 21 forks source link

OrderCloud SSO support #8

Open digitalParkour opened 2 years ago

digitalParkour commented 2 years ago

This project has been a huge help! Thank you so much.

Heads up, the current OcProvider doesn't play nice for implementing OrderCloud SSO. There is a need to provide a callback url that receives the authenticated users OC token (see AppStartUrl in https://ordercloud.io/knowledge-base/sso-via-openid-connect regarding). At first I tried handling it with a static page, like /sso?token={0}, dispatching a newly crafted "ssologin" action similar to the login thunk but only needing the already available token. Long story short, it can be really tricky getting it right due to the timing of all the activity in the OcProvider flipping the ocAuth flags and getting the default user for ocUser. The default anonymous user kept finishing last and overriding my logged in user. I ended up removing the static /sso callback to simply extend the logic in the OcProvider to look for query.token. This felt nice since it could support any page route as the callback.

Anyhow, it would be really nice to add support in this project for the SSO callback. Even stubbing in the /createUser and /syncUser endpoints would be fantastic (or perhaps in the @ordercloud/catalyst project).

BTW, really awesome to see Azure B2C SSO working through OrderCloud!

oliverheywood451 commented 2 years ago

@digitalParkour Thanks for creating the issue. I really like your idea of stubbing out the integration event endpoints. I will add that to @ordercloud/catalyst and to this project.

BTW, excited to hear you're using @ordercloud/catalyst. It's in a stage where we're looking for community feedback, so feel free to create an issue there for anything confusing or not-ideal. Thanks!