module "api_explorer_app_client" {
  source = "../../modules/auth0_client"

  name                                = "API Explorer Application"
  description                         = "Managed by Terraform"
  is_token_endpoint_ip_header_trusted = true
  oidc_conformant                     = true

  jwt_configuration = [
    {
      alg                 = "RS256"
      lifetime_in_seconds = 36000
      secret_encoded      = false
      scopes              = {}
    }
  ]

  grant_types = [
    "authorization_code",
    "client_credentials",
    "implicit",
    "refresh_token",
  ]
}

module "api_marketing_client" {
  source = "../../modules/auth0_client"

  name                                = "api-marketing"
  description                         = "Managed by Terraform"
  oidc_conformant                     = true
  is_token_endpoint_ip_header_trusted = false

  jwt_configuration = [
    {
      lifetime_in_seconds = 300
      secret_encoded      = false
      alg                 = "RS256"
      scopes              = {}
    }
  ]

  grant_types = [
    "authorization_code",
    "client_credentials",
    "implicit",
    "refresh_token",
  ]
}

module "apollo_api_client" {
  source = "../../modules/auth0_client"

  name                                = "apollo-api"
  description                         = "Managed by Terraform"
  oidc_conformant                     = true
  is_token_endpoint_ip_header_trusted = false

  jwt_configuration = [
    {
      lifetime_in_seconds = 300
      secret_encoded      = false
      alg                 = "RS256"
      scopes              = {}
    }
  ]

  grant_types = [
    "authorization_code",
    "client_credentials",
    "implicit",
    "refresh_token",
  ]
}

module "apollo_go_client" {
  source = "../../modules/auth0_client"

  name                                = "apollo-go"
  description                         = "Managed by Terraform"
  oidc_conformant                     = true
  is_token_endpoint_ip_header_trusted = false
  app_type                            = "native"
  logo_uri                            = "https://static.independent.co.uk/s3fs-public/thumbnails/image/2017/09/12/11/naturo-monkey-selfie.jpg?w968h681"
  sso                                 = true
  token_endpoint_auth_method          = "none"

  jwt_configuration = [
    {
      lifetime_in_seconds = 300
      secret_encoded      = false
      alg                 = "RS256"
      scopes              = {}
    }
  ]

  grant_types = [
    "authorization_code",
    "http://auth0.com/oauth/grant-type/mfa-oob",
    "http://auth0.com/oauth/grant-type/mfa-otp",
    "http://auth0.com/oauth/grant-type/mfa-recovery-code",
    "refresh_token",
  ]

  allowed_logout_urls = [
    "https://auth.expo.io/@sonymusic/apollogo",
    "https://auth.expo.io/@colevort/apollo-go",
    "https://expo.io/@colevort/apollogo?release-channel=qa",
    "https://auth.expo.io/@colevort/apollogo",
  ]

  allowed_origins = [
    "https://auth.expo.io/@sonymusic/apollogo",
    "https://auth.expo.io/@colevort/apollo-go",
    "https://expo.io/@colevort/apollogo?release-channel=qa",
    "https://auth.expo.io/@colevort/apollogo",
    "http://localhost:19001",
    "http://localhost:8081",
    "http://localhost:19000",
  ]

  callbacks = [
    "https://auth.expo.io/@sonymusic/apollogo",
    "https://auth.expo.io/@colevort/apollo-go",
    "https://expo.io/@colevort/apollo-go?release-channel=qa",
    "https://expo.io/@colevort/apollogo?release-channel=qa",
    "https://auth.expo.io/@colevort/apollogo",
    "org.reactjs.native.example.awesomeapp://sme-dna.auth0.com/ios/org.reactjs.native.example.AwesomeApp/callback",
    "https://sme-dna.us8.webtask.io/auth0-authentication-api-debugger",
    "apollogo://callback",
    "exp://localhost:19000/callback",
    "apollogo://email",
    "apollogodev://email",
    "apollogodev://callback",
  ]


  web_origins = [
    "https://auth.expo.io",
    "https://sme-dna.us8.webtask.io/auth0-authentication-api-debugger",
    "http://localhost:8081",
    "http://localhost:19000",
    "http://localhost:19001",
  ]
}

//  mobile {
//    android {
//      app_package_name         = "com.sony.apollogo"
//      sha256_cert_fingerprints = [] // TODO: can't be empty, probably validation error
//    }
//  }

module "client_client" {
  source = "../../modules/auth0_client"

  name                                = "Client"
  description                         = "Managed by Terraform"
  is_token_endpoint_ip_header_trusted = false
  oidc_conformant                     = true
  token_endpoint_auth_method          = "none"
  app_type                            = "spa"

  jwt_configuration = [
    {
      alg                 = "RS256"
      lifetime_in_seconds = 86400
      secret_encoded      = false
      scopes              = {}
    }
  ]

  grant_types = [
    "authorization_code",
    "implicit",
    "refresh_token",
  ]
}

module "default_app_client" {
  source = "../../modules/auth0_client"

  name                                = "Default App"
  description                         = "Managed by Terraform"
  oidc_conformant                     = true
  is_token_endpoint_ip_header_trusted = false

  jwt_configuration = [
    {
      lifetime_in_seconds = 36000
      secret_encoded      = false
      alg                 = "RS256"
      scopes              = {}
    }
  ]

  grant_types = [
    "authorization_code",
    "client_credentials",
    "implicit",
    "refresh_token",
  ]
}

module "export_logs_client" {
  source = "../../modules/auth0_client"

  name                                = "Export Logs"
  description                         = "Managed by Terraform"
  is_token_endpoint_ip_header_trusted = false
  oidc_conformant                     = true
  jwt_configuration = [
    {
      alg                 = "RS256"
      lifetime_in_seconds = 300
      secret_encoded      = false
      scopes              = {}
    }
  ]

  grant_types = [
    "authorization_code",
    "client_credentials",
    "implicit",
    "refresh_token",
  ]
}

module "fe_marketing_client" {
  source = "../../modules/auth0_client"

  name                                = "fe-marketing"
  description                         = "Managed by Terraform"
  is_token_endpoint_ip_header_trusted = false
  oidc_conformant                     = true
  token_endpoint_auth_method          = "none"
  app_type                            = "spa"

  jwt_configuration = [
    {
      alg                 = "RS256"
      lifetime_in_seconds = 86400
      secret_encoded      = false
      scopes              = {}
    }
  ]

  grant_types = [
    "authorization_code",
    "implicit",
    "refresh_token",
  ]

  allowed_logout_urls = [
    "https://dev-mct.apollo.stream/login",
    "https://staging-mct.apollo.stream/login",
    "https://dev-mct-s3test.apollo.stream/login",
    "https://qa-mct.apollo.stream/login",
    "https://uat-mct.apollo.stream/login",
    "https://dev-mct-ui.apollo.stream/login",
    "http://localhost:3000/login",
  ]

  callbacks = [
    "https://dev-mct.apollo.stream/auth/callback",
    "https://staging-mct.apollo.stream/auth/callback",
    "https://dev-mct-s3test.apollo.stream/auth/callback",
    "https://qa-mct.apollo.stream/auth/callback",
    "https://uat-mct.apollo.stream/auth/callback",
    "https://dev-mct-ui.apollo.stream/auth/callback",
    "http://localhost:3000/auth/callback",
    "http://localhost:3001/auth/callback",
    "https://sme-dna.us8.webtask.io/auth0-authentication-api-debugger",
  ]

  allowed_origins = [
    "https://dev-mct.apollo.stream/auth/callback",
    "https://staging-mct.apollo.stream/auth/callback",
    "https://dev-mct-s3test.apollo.stream/auth/callback",
    "https://qa-mct.apollo.stream/auth/callback",
    "https://uat-mct.apollo.stream/auth/callback",
    "http://localhost:3000",
    "http://localhost:3001",
    "https://dev-mct-ui.apollo.stream/auth/callback",
    "http://localhost:3000/auth/callback",
    "http://localhost:3001/auth/callback",
  ]

  web_origins = [
    "https://dev-mct.apollo.stream",
    "https://dev-mct.apollo.stream/auth/callback",
    "https://staging-mct.apollo.stream",
    "https://staging-mct.apollo.stream/auth/callback",
    "https://dev-mct-s3test.apollo.stream/auth/callback",
    "https://qa-mct.apollo.stream",
    "https://qa-mct.apollo.stream/auth/callback",
    "https://uat-mct.apollo.stream",
    "https://uat-mct.apollo.stream/auth/callback",
    "http://localhost:3000",
    "http://localhost:3001",
    "https://dev-mct-ui.apollo.stream",
    "https://dev-mct-ui.apollo.stream/auth/callback",
    "http://localhost:3000/auth/callback",
  ]
}

module "fe_web_portal_client" {
  source = "../../modules/auth0_client"

  name                                = "fe-web-portal"
  description                         = "Apollo Web DEV, QA, STAGING. Managed by Terraform"
  is_token_endpoint_ip_header_trusted = false
  oidc_conformant                     = true
  token_endpoint_auth_method          = "none"
  app_type                            = "spa"

  jwt_configuration = [
    {
      alg                 = "RS256"
      lifetime_in_seconds = 240
      secret_encoded      = false
      scopes              = {}
    }
  ]

  grant_types = [
    "authorization_code",
    "http://auth0.com/oauth/grant-type/mfa-oob",
    "http://auth0.com/oauth/grant-type/mfa-otp",
    "http://auth0.com/oauth/grant-type/mfa-recovery-code",
    "implicit",
    "refresh_token",
  ]

  allowed_logout_urls = [
    "https://dev.apollo.stream/login",
    "https://staging.apollo.stream/login",
    "https://qa.apollo.stream/login",
    "https://apollo.localhost:2000/login",
    "https://sme-dna.us8.webtask.io/auth0-authentication-api-debugger",
  ]

  callbacks = [
    "https://dev.apollo.stream",
    "https://dev.apollo.stream/auth/callback",
    "https://staging.apollo.stream",
    "https://staging.apollo.stream/auth/callback",
    "https://qa.apollo.stream",
    "https://qa.apollo.stream/auth/callback",
    "https://apollo.localhost:2000",
    "https://apollo.localhost:2000/auth/callback",
    "https://sme-dna.us8.webtask.io/auth0-authentication-api-debugger",
  ]

  allowed_origins = [
    "https://dev.apollo.stream",
    "https://staging.apollo.stream",
    "https://qa.apollo.stream",
    "https://apollo.localhost:2000",
    "https://sme-dna.us8.webtask.io/auth0-authentication-api-debugger",
  ]

  web_origins = [
    "https://dev.apollo.stream",
    "https://staging.apollo.stream",
    "https://qa.apollo.stream",
    "https://apollo.localhost:2000",
    "https://sme-dna.us8.webtask.io/auth0-authentication-api-debugger",
  ]
}

module "management_api_client" {
  source = "../../modules/auth0_client"

  name                                = "management-api"
  description                         = "Managed by Terraform"
  is_token_endpoint_ip_header_trusted = false
  oidc_conformant                     = true

  jwt_configuration = [
    {
      alg                 = "RS256"
      lifetime_in_seconds = 300
      secret_encoded      = false
      scopes              = {}
    }
  ]

  grant_types = [
    "authorization_code",
    "client_credentials",
    "implicit",
    "refresh_token",
  ]
}

module "mct_api_client" {
  source = "../../modules/auth0_client"

  name                                = "MCT-API"
  description                         = "Managed by Terraform"
  is_token_endpoint_ip_header_trusted = false
  oidc_conformant                     = true

  jwt_configuration = [
    {
      alg                 = "RS256"
      lifetime_in_seconds = 300
      secret_encoded      = false
      scopes              = {}
    }
  ]

  callbacks = [
    "https://sme-dna.us8.webtask.io/auth0-authentication-api-debugger",
    "https://dev-mct.apollo.stream",
    "https://dev-mct.apollo.stream/auth/callback",
    "https://dev-mct.localhost:2000",
  ]

  grant_types = [
    "authorization_code",
    "client_credentials",
    "implicit",
    "refresh_token",
  ]
}

module "portal_private_api_test_application_client" {
  source = "../../modules/auth0_client"

  name                                = "PortalPrivateAPI (Test Application)"
  description                         = "Managed by Terraform"
  is_token_endpoint_ip_header_trusted = false
  oidc_conformant                     = true

  jwt_configuration = [
    {
      alg                 = "RS256"
      lifetime_in_seconds = 36000
      secret_encoded      = false
      scopes              = {}
    }
  ]

  grant_types = [
    "client_credentials",
  ]
}

module "private_api_client" {
  source = "../../modules/auth0_client"

  name                                = "PrivateAPI"
  description                         = "Managed by Terraform"
  is_token_endpoint_ip_header_trusted = false
  oidc_conformant                     = true

  jwt_configuration = [
    {
      alg                 = "RS256"
      lifetime_in_seconds = 300
      secret_encoded      = false
      scopes              = {}
    }
  ]

  grant_types = [
    "authorization_code",
    "client_credentials",
    "http://auth0.com/oauth/grant-type/mfa-oob",
    "http://auth0.com/oauth/grant-type/mfa-otp",
    "http://auth0.com/oauth/grant-type/mfa-recovery-code",
    "http://auth0.com/oauth/grant-type/password-realm",
    "implicit",
    "password",
    "refresh_token",
  ]

  callbacks = [
    "https://sme-dna.us8.webtask.io/auth0-authentication-api-debugger"
  ]

  allowed_logout_urls = [
    "https://sme-dna.us8.webtask.io/auth0-authentication-api-debugger"
  ]
}

module "sma_api_test_application_client" {
  source = "../../modules/auth0_client"

  name                                = "SMA API (Test Application)"
  is_token_endpoint_ip_header_trusted = true
  oidc_conformant                     = true

  jwt_configuration = [
    {
      alg                 = "RS256"
      lifetime_in_seconds = 36000
      secret_encoded      = false
      scopes              = {}
    }
  ]

  grant_types = [
    "client_credentials"
  ]
}

module "terraform_test_client" {
  source = "../../modules/auth0_client"

  name                                = "terraform-test"
  description                         = "Managed by Terraform"
  is_token_endpoint_ip_header_trusted = false
  oidc_conformant                     = true

  jwt_configuration = [
    {
      alg                 = "RS256"
      lifetime_in_seconds = 36000
      secret_encoded      = false
      scopes              = {}
    }
  ]

  grant_types = [
    "client_credentials",
    "authorization_code",
  ]
}

module "atlas_um_client" {
  source = "../../modules/auth0_client"

  name                                = "dev-um.atlas.stream"
  description                         = "Managed by Terraform"
  is_token_endpoint_ip_header_trusted = false
  oidc_conformant                     = true

  jwt_configuration = [
    {
      alg                 = "RS256"
      lifetime_in_seconds = 36000
      secret_encoded      = false
      scopes              = {}
    }
  ]

  grant_types = [
    "client_credentials",
    "authorization_code",
  ]
}

module "test_test_application_client" {
  source = "../../modules/auth0_client"

  name                                = "Test (Test Application)"
  description                         = "Managed by Terraform"
  is_token_endpoint_ip_header_trusted = false
  oidc_conformant                     = true

  jwt_configuration = [
    {
      alg                 = "RS256"
      lifetime_in_seconds = 36000
      secret_encoded      = false
      scopes              = {}
    }
  ]

  grant_types = [
    "authorization_code",
    "client_credentials",
    "implicit",
    "refresh_token",
  ]
}

module "the_whitelist_client" {
  source = "../../modules/auth0_client"

  name                                = "The Whitelist"
  description                         = "Managed by Terraform"
  is_token_endpoint_ip_header_trusted = false
  oidc_conformant                     = false
  token_endpoint_auth_method          = "none"
  app_type                            = "spa"

  jwt_configuration = [
    {
      alg                 = "RS256"
      lifetime_in_seconds = 60
      secret_encoded      = false
      scopes              = {}
    }
  ]

  grant_types = [
    "authorization_code",
    "implicit",
    "refresh_token",
  ]

  allowed_logout_urls = [
    "http://localhost:3000",
    "https://web.whtlst.in",
    "https://bot.whtlst.in",
  ]

  callbacks = [
    "http://localhost:3000",
    "https://web.whtlst.in",
    "https://bot.whtlst.in",
  ]

  web_origins = [
    "http://localhost:3000",
    "https://web.whtlst.in",
    "https://bot.whtlst.in",
  ]
}
