Skip to content

feat: Add Okta ODIC support #99

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

chrisAlwinYS
Copy link
Contributor

Adding Okta ODIC support. #73

Also fixed the need to add a NEXT_PUBLIC_SERVER_URL env variable was fixed, which can still be used but is not necessary now.

Let me know if anything needs changing.

This has been tested on Payload 3.35.1 with a MongoDB.
I have not tested all the user profile saving, purely getting it to work for now.
The only bug I have seen is too logout their needs to be a browser refresh. I assume something to do with session values, not sure if it's just affecting my implementation or is a wider bug.

@materazu
Copy link

materazu commented Apr 24, 2025

Amazing, I was working on it yesterday too, perfect PR!
To log out, you simply need to override the logout button on admin panel, to be able to call the plugin api session logout (/api/admin/session/logout) ; that's the solution I found. Maybe we could just document it?

'use client'

import React from 'react'
import { LogOutIcon } from '@payloadcms/ui/icons/LogOut'
import { useTranslation } from '@payloadcms/ui/providers/Translation'
import { Link } from '@payloadcms/ui/elements/Link'
import { useRouter } from 'next/navigation'

const baseClass = 'nav'

const LogoutButton: React.FC<{
  tabIndex?: number
}> = ({ tabIndex = 0 }) => {
  const { t } = useTranslation()
  const router = useRouter()

  const handleLogout = async (e: React.MouseEvent) => {
    e.preventDefault()
    
    await fetch('/api/admin/session/logout', {
      credentials: 'include',
    })
    
    router.push('/admin/logout')
  }

  return (
    <Link
      aria-label={t('authentication:logOut')}
      className={`${baseClass}__log-out`}
      href="#"
      onClick={handleLogout}
      prefetch={false}
      tabIndex={tabIndex}
      title={t('authentication:logOut')}
    >
      <LogOutIcon />
    </Link>
  )
}

export default LogoutButton

@chrisAlwinYS
Copy link
Contributor Author

Thankyou!! Happy to add to the PR as it is likely related. If I do probable best left as an optional component to be added. Or could just leave it as documented. Happy to take opinions on that?

@materazu
Copy link

I think it's best to reference it in the documentation, as with the rest of the proposed configurations.

@chrisAlwinYS
Copy link
Contributor Author

Will do, let's keep it in the docs.

For me testing the logout component didn't work, I keep getting redirected back to the admin panel. The URL/api/admin/session/logout doesn't exist... is there documentation on that? the closest I could find was /api/{userCollection}/logout which didn't work either.

Will keep testing if I find a way that works ill up date the pull request with the needed documentaion. As mentioned before after refesh the logout functionality works so thinking its a cookie not loading correctly or being checked and cleared.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants