LoginServiceButtons.tsx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import React from 'react';
  2. import config from 'app/core/config';
  3. const loginServices: () => LoginServices = () => ({
  4. saml: {
  5. enabled: config.samlEnabled,
  6. name: 'SAML',
  7. className: 'github',
  8. icon: 'key',
  9. },
  10. google: {
  11. enabled: config.oauth.google,
  12. name: 'Google',
  13. },
  14. github: {
  15. enabled: config.oauth.github,
  16. name: 'GitHub',
  17. },
  18. gitlab: {
  19. enabled: config.oauth.gitlab,
  20. name: 'GitLab',
  21. },
  22. grafanacom: {
  23. enabled: config.oauth.grafana_com,
  24. name: 'Grafana.com',
  25. hrefName: 'grafana_com',
  26. icon: 'grafana_com',
  27. },
  28. oauth: {
  29. enabled: config.oauth.generic_oauth,
  30. name: 'OAuth',
  31. icon: 'sign-in',
  32. hrefName: 'generic_oauth',
  33. },
  34. });
  35. export interface LoginService {
  36. enabled: boolean;
  37. name: string;
  38. hrefName?: string;
  39. icon?: string;
  40. className?: string;
  41. }
  42. export interface LoginServices {
  43. [key: string]: LoginService;
  44. }
  45. export const LoginServiceButtons = () => {
  46. const keyNames = Object.keys(loginServices());
  47. const serviceElements = keyNames.map(key => {
  48. const service: LoginService = loginServices()[key];
  49. return service.enabled ? (
  50. <a
  51. key={key}
  52. className={`btn btn-medium btn-service btn-service--${service.className || key} login-btn`}
  53. href={`login/${service.hrefName ? service.hrefName : key}`}
  54. target="_self"
  55. >
  56. <i className={`btn-service-icon fa fa-${service.icon ? service.icon : key}`} />
  57. Sign in with {service.name}
  58. </a>
  59. ) : null;
  60. });
  61. return <div className="login-oauth text-center">{serviceElements}</div>;
  62. };