zuiidea / antd-admin

An excellent front-end solution for enterprise applications built upon Ant Design and UmiJS
https://antd-admin.zuiidea.com
MIT License
9.64k stars 2.52k forks source link

Okta integration #1015

Closed joepardi closed 5 years ago

joepardi commented 5 years ago

Has anyone gotten Ant Admin to use Okta for its login? I have Okta working on a regular Material-UI React application but can't get it to work with Ant Admin. Any help would be appreciated.

superlbr commented 5 years ago

why not use okta-auth-js, don't be trapped in react

joepardi commented 5 years ago

I have to use React as that's my teams' preferred choice. We also use Ant Design but no one has integrated with Okta yet. Since this is a new application, I thought Ant Admin was good for the initial scaffolding but the dynamic routes done by umi/dva are making it a challenge to put the correct Okta hooks in place. I swapped out the standard Ant Admin login page and put in the SignInWidget widget. I can get the app to display the Okta login page and post the credentials back to Okta. I can see the /implicit/callback route being invoked. The Okta cookies are being created, but for some reason the equivalent Okta objects are not being parsed and created within localStorage. Since this doesn't occur, auth.isAuthenticated() returns false and thus the app is not considered logged in yet.

I'l play around some more but was hoping someone already solved this before me.

superlbr commented 5 years ago

how about put a minimal demo to have a look?

joepardi commented 5 years ago

@superlbr - I have a minimum version mostly working. Feel free to submit changes. The current state of it:

ISSUES:

  1. routes are not working correctly after initial login. They work after a page refresh, however.
  2. session timeout doesn't work cleanly

NOTES: A. public repo is https://github.com/joepardi/antadminokta B. see /mock/user.js for the Okta user to test with ... adamant@sample.com is setup on the Okta service. C. see the //OKTA marked comments within the code

I'll get some more time later today to see if I can fix the remaining two issues.

superlbr commented 5 years ago

ah, you need use route in umi style not 'react-router-dom'

joepardi commented 5 years ago

Agreed. I removed the definition for /implicit/callback from /layouts/index.js and added /pages/implicit/callback/index.js, as you stated. I took the ImplicitCallback class provided by @okta/okta-react and switched it to use umi. It still doesn't work as it's not getting invoked.

These changes are now in the repo.

joepardi commented 5 years ago

@superlbr - your changes fixed the routing issues (hooray!). One small thing, however. The new callback entry in /mock/route.js shows up on the sidebar menu. Any suggestion on how to get it to not show but still remain valid as a route? Can that be done in the JSON or does it need to be hidden in the code somewhere?

menu

joepardi commented 5 years ago

Found it ... by setting menuParentId: '-1', the layout's filters it out. @superlbr ... thanks for all your help.