From 49be9e21c3c4f6e24c83dcbb41136127b03e8d83 Mon Sep 17 00:00:00 2001 From: Ani Ravi <5902976+aniravi24@users.noreply.github.com> Date: Wed, 2 Jun 2021 08:46:45 -0700 Subject: [PATCH] chore: Universal Linking for Android (#2324) * android assetlinks.json config * try renaming html to json * update env example * chore: fix styling * chore: styling part 2 * test: add spec for android assetlinks * minor fixes * minor fixes * remove android sha256 value from env example * add default sh256 value Co-authored-by: Muhsin Keloth Co-authored-by: Sojan Jose --- .env.example | 4 ++++ app/controllers/android_app_controller.rb | 5 +++++ app/views/android_app/assetlinks.json.erb | 12 ++++++++++++ config/routes.rb | 1 + spec/controllers/android_assetlinks_spec.rb | 10 ++++++++++ 5 files changed, 32 insertions(+) create mode 100644 app/controllers/android_app_controller.rb create mode 100644 app/views/android_app/assetlinks.json.erb create mode 100644 spec/controllers/android_assetlinks_spec.rb diff --git a/.env.example b/.env.example index 8d03180a8..08e72816e 100644 --- a/.env.example +++ b/.env.example @@ -116,6 +116,10 @@ SLACK_CLIENT_SECRET= ### Change this env variable only if you are using a custom build mobile app ## Mobile app env variables IOS_APP_ID=6C953F3RX2.com.chatwoot.app +ANDROID_BUNDLE_ID=com.chatwoot.app + +# https://developers.google.com/android/guides/client-auth (use keytool to print the fingerprint in the first section) +ANDROID_SHA256_CERT_FINGERPRINT=AC:73:8E:DE:EB:56:EA:CC:10:87:02:A7:65:37:7B:38:D4:5D:D4:53:F8:3B:FB:D3:C6:28:64:1D:AA:08:1E:D8 ### Smart App Banner diff --git a/app/controllers/android_app_controller.rb b/app/controllers/android_app_controller.rb new file mode 100644 index 000000000..c403d7756 --- /dev/null +++ b/app/controllers/android_app_controller.rb @@ -0,0 +1,5 @@ +class AndroidAppController < ApplicationController + def assetlinks + render layout: false + end +end diff --git a/app/views/android_app/assetlinks.json.erb b/app/views/android_app/assetlinks.json.erb new file mode 100644 index 000000000..575ca3b56 --- /dev/null +++ b/app/views/android_app/assetlinks.json.erb @@ -0,0 +1,12 @@ +[ + { + "relation": ["delegate_permission/common.handle_all_urls"], + "target": { + "namespace": "android_app", + "package_name": "<%= ENV['ANDROID_BUNDLE_ID'] %>", + "sha256_cert_fingerprints": [ + "<%= ENV['ANDROID_SHA256_CERT_FINGERPRINT'] %>" + ] + } + } +] \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 499588e42..667346c02 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -232,6 +232,7 @@ Rails.application.routes.draw do # ---------------------------------------------------------------------- # Routes for external service verifications get 'apple-app-site-association' => 'apple_app#site_association' + get '.well-known/assetlinks.json' => 'android_app#assetlinks' # ---------------------------------------------------------------------- # Internal Monitoring Routes diff --git a/spec/controllers/android_assetlinks_spec.rb b/spec/controllers/android_assetlinks_spec.rb new file mode 100644 index 000000000..a44ef111a --- /dev/null +++ b/spec/controllers/android_assetlinks_spec.rb @@ -0,0 +1,10 @@ +require 'rails_helper' + +describe '.well-known/assetlinks.json', type: :request do + describe 'GET /.well-known/assetlinks.json' do + it 'successfully retrieves assetlinks.json file' do + get '/.well-known/assetlinks.json' + expect(response).to have_http_status(:success) + end + end +end