graphql-auth.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * GraphQL Authentication Configuration
  4. *
  5. * Defines which GraphQL operations require X-STOREFRONT-KEY authentication.
  6. * X-STOREFRONT-KEY is the generic, header for all client types:
  7. * - Mobile apps
  8. * - Web storefronts
  9. * - Headless commerce
  10. * - Admin dashboards
  11. * - Third-party integrations *
  12. */
  13. return [
  14. /**
  15. * Public GraphQL operations that don't require X-STOREFRONT-KEY header
  16. *
  17. * AUTHENTICATION STRATEGY:
  18. * - X-STOREFRONT-KEY: ALWAYS required (identifies client/app)
  19. * - Bearer Token: Required only for user-specific operations
  20. *
  21. * All operations require X-STOREFRONT-KEY. Then:
  22. * - Public operations: X-STOREFRONT-KEY only
  23. * - User operations: X-STOREFRONT-KEY + Bearer token (Sanctum)
  24. * - Admin operations: X-STOREFRONT-KEY + Admin Bearer token
  25. *
  26. * Empty list = All operations require X-STOREFRONT-KEY
  27. */
  28. 'public_operations' => [
  29. '__schema',
  30. '__type',
  31. ],
  32. /**
  33. * Protected operations that require X-STOREFRONT-KEY header
  34. *
  35. * Leave this as an empty array to use blacklist approach (recommended).
  36. * If you list operations here, they WILL require authentication.
  37. * Unlisted operations with this non-empty array will NOT require auth.
  38. *
  39. * BEST PRACTICE: Keep this empty and use public_operations instead
  40. * This way: protected_operations = everything NOT in public_operations
  41. */
  42. 'protected_operations' => [
  43. ],
  44. /**
  45. * Enable selective authentication
  46. *
  47. * true: Use whitelist approach (public_operations)
  48. * false: Use blacklist approach (protected_operations)
  49. *
  50. * RECOMMENDED: true (whitelist is more secure)
  51. */
  52. 'use_whitelist' => true,
  53. /**
  54. * Skip authentication for introspection queries
  55. * Allow GraphQL tools and playground to inspect schema without key
  56. */
  57. 'allow_introspection' => true,
  58. /**
  59. * Detailed logging for authentication
  60. * Set to 'true' to log all authentication checks
  61. */
  62. 'log_auth_checks' => env('GRAPHQL_AUTH_LOG', false),
  63. /**
  64. * Custom error messages
  65. */
  66. 'messages' => [
  67. 'missing_key' => 'X-STOREFRONT-KEY header is required for this operation',
  68. 'invalid_key' => 'Invalid or expired API key',
  69. 'rate_limit' => 'Rate limit exceeded. Please try again later.',
  70. ],
  71. ];