OAuthEndpointsTable.tsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import { useParams } from 'common'
  2. import { Card, CardContent, cn } from 'ui'
  3. import {
  4. PageSection,
  5. PageSectionContent,
  6. PageSectionDescription,
  7. PageSectionMeta,
  8. PageSectionSummary,
  9. PageSectionTitle,
  10. } from 'ui-patterns'
  11. import { Input } from 'ui-patterns/DataInputs/Input'
  12. import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
  13. import { GenericSkeletonLoader } from 'ui-patterns/ShimmeringLoader'
  14. import { useOpenIDConfigurationQuery } from '@/data/oauth-server-apps/oauth-openid-configuration-query'
  15. interface OAuthEndpointsTableProps {
  16. isLoading?: boolean
  17. className?: string
  18. }
  19. export const OAuthEndpointsTable = ({
  20. isLoading: isLoadingProp = false,
  21. className,
  22. }: OAuthEndpointsTableProps) => {
  23. const { ref: projectRef } = useParams()
  24. const { data: openidConfig, isLoading: isEndpointsLoading } = useOpenIDConfigurationQuery(
  25. { projectRef },
  26. { enabled: !isLoadingProp }
  27. )
  28. const isLoading = isLoadingProp || isEndpointsLoading
  29. const endpoints = [
  30. {
  31. name: 'Authorization endpoint',
  32. value: openidConfig?.authorization_endpoint,
  33. },
  34. {
  35. name: 'Token endpoint',
  36. value: openidConfig?.token_endpoint,
  37. },
  38. {
  39. name: 'JWKS endpoint',
  40. value: openidConfig?.jwks_uri,
  41. },
  42. {
  43. name: 'OIDC discovery',
  44. value: openidConfig?.issuer
  45. ? `${openidConfig.issuer}/.well-known/openid-configuration`
  46. : undefined,
  47. },
  48. ]
  49. return (
  50. <PageSection className={cn(className)}>
  51. <PageSectionMeta>
  52. <PageSectionSummary>
  53. <PageSectionTitle>OAuth Endpoints</PageSectionTitle>
  54. <PageSectionDescription>
  55. Share these endpoints with third-party applications that need to integrate with your
  56. OAuth 2.1 server.
  57. </PageSectionDescription>
  58. </PageSectionSummary>
  59. </PageSectionMeta>
  60. <PageSectionContent>
  61. <Card>
  62. <CardContent className="flex flex-col gap-4 pt-0 divide-y">
  63. {isLoading ? (
  64. <GenericSkeletonLoader className="mt-4" />
  65. ) : (
  66. endpoints.map((endpoint) => (
  67. <FormItemLayout
  68. key={endpoint.name}
  69. layout="horizontal"
  70. isReactForm={false}
  71. label={endpoint.name}
  72. className="mt-4"
  73. >
  74. <Input readOnly copy value={endpoint.value ?? ''} />
  75. </FormItemLayout>
  76. ))
  77. )}
  78. </CardContent>
  79. </Card>
  80. </PageSectionContent>
  81. </PageSection>
  82. )
  83. }