Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Firebase Hosting for apple-app-site-association
{
"hosting": {
"headers": [
{
"source": "/.well-known/apple-app-site-association",
"headers": [{"key": "Content-Type", "value": "application/json"}]
}
]
}
}
@endryha

This comment has been minimized.

Copy link

@endryha endryha commented Apr 10, 2019

did you successfully upload custom apple-app-site-association file with this configuration? thank you

@annpt1

This comment has been minimized.

Copy link

@annpt1 annpt1 commented May 17, 2019

I successfully update apple-app-site-association with this firebase configuration

@cgbrucezjy

This comment has been minimized.

Copy link

@cgbrucezjy cgbrucezjy commented Sep 3, 2019

I'm getting an issue where everything within an array is deleted only showing []
ie. {"applinks":{"apps":[],"details":[]}}

@darrenyaoyao

This comment has been minimized.

Copy link

@darrenyaoyao darrenyaoyao commented Dec 5, 2019

I'm getting an issue where everything within an array is deleted only showing []
ie. {"applinks":{"apps":[],"details":[]}}

add this works for me

    "appAssociation": "NONE",
@stleamist

This comment has been minimized.

Copy link

@stleamist stleamist commented Jan 19, 2020

I'm getting an issue where everything within an array is deleted only showing []
ie. {"applinks":{"apps":[],"details":[]}}

add this works for me

    "appAssociation": "NONE",

Thanks a lot! You saved my day 😄

@Blackjacx

This comment has been minimized.

Copy link

@Blackjacx Blackjacx commented Feb 6, 2020

which commands do you use to upload the apple-app-site-association file and where exactly must it be? Can somebody pls post how the firebase json has to look that this works?

@stleamist

This comment has been minimized.

Copy link

@stleamist stleamist commented Feb 6, 2020

@Blackjacx

which commands do you use to upload the apple-app-site-association file and where exactly must it be? Can somebody pls post how the firebase json has to look that this works?

There are 4 things to check:

  1. The apple-app-site-association file should be placed at the root of your server or in the .well-known subdirectory.
  2. The apple-app-site-association file should be served on the HTTPS. (This is done by Firebase.)
  3. The apple-app-site-association file should be served as the application/json MIME type, without appending .json to the filename. By setting a custom header in firebase.json, it can be done.
  4. Even though the Dynamic Links is not set, the Firebase overrides the apple-app-site-association file in / and /.well-known to its own file by default. To avoid this, the appAssociation property in firebase.json should be set to NONE.

Then the firebase.json file should be like below:

{
  "hosting": {
    "public": "public",
    "headers": [
      {
        "source": "/.well-known/apple-app-site-association",
        "headers": [
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ]
      }
    ],
    "appAssociation": "NONE"
  }
}
@Blackjacx

This comment has been minimized.

Copy link

@Blackjacx Blackjacx commented Feb 7, 2020

Thx for clarification 👍 This will help a lot of ppl I think since this approach is not straight forward like otherwise known from Firebase 🥇

@mbleigh

This comment has been minimized.

Copy link
Owner Author

@mbleigh mbleigh commented Feb 7, 2020

FWIW we're looking into this as a bug -- you shouldn't have to set appAssociation to NONE in order to serve your own file. We should also be picking up the MIME type automatically. No timeline on when we'll be able to push out a fix, but we're looking at it.

@asikand

This comment has been minimized.

Copy link

@asikand asikand commented Feb 10, 2020

I still can't get this to work
apple-app-site-association

{
	"applinks":{
			"apps":[],
			"details":[{"appID":"TEAMD.BUNDLEID","paths":["/*"]}]
        },
	"webcredentials": {
		  "apps": ["TEAMID.BUNDLEID"]
	}
}

Firebase.json


{
  "hosting": {
    "public": "public",
    "headers": [
      {
        "source": "/.well-known/apple-app-site-association",
        "headers": [
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ]
      }
    ],
    "appAssociation": "NONE"
  }
}

apple-app-association.json file has been placed in root, public, and .wellknown directories.

When I try to access https://HOSTINGURL/apple-app-site-association my computer downloads a .gz file that is seemingly empty. I also tried to set up the apple-app-site-association under Dynamic Links instead of Hosting and that remains empty despite me putting in a Team ID and App Store ID under project settings

{"applinks":{"apps":[],"details":[]}}

@asikand

This comment has been minimized.

Copy link

@asikand asikand commented Feb 10, 2020

I know it exists because this gist https://gist.github.com/mbleigh/9c8680cf319ace2f506f57380da66e7d results in this output:

Fetching /.wellknown/apple-app-site-association.json
Fetched  /.wellknown/apple-app-site-association.json
Fetching /404.html
Fetched  /404.html
Fetching /__/firebase/init.js
Fetched  /__/firebase/init.js
Fetching /__/firebase/init.json
Fetched  /__/firebase/init.json
Fetching /apple-app-site-association.json
Fetched  /apple-app-site-association.json
Fetching /index.html
Fetched  /index.html

@stleamist

This comment has been minimized.

Copy link

@stleamist stleamist commented Feb 10, 2020

@asikand Have you tried removing .json from the filename? The file should be stored without any extension.

@asikand

This comment has been minimized.

Copy link

@asikand asikand commented Feb 10, 2020

I tried it both with and without .json from the file name. I thought the whole gz problem had to do with it not correctly identifying the right file type.

My AASA is now working through the Dynamic Links page.link url: https://freeyourtaste.page.link/apple-app-site-association

But I still can't get it working with hosting.

@asikand

This comment has been minimized.

Copy link

@asikand asikand commented Feb 10, 2020

@stleamist I re-uploaded the files and deployed them to hosting this time without the .json file extension.

Now if I access:
https://fyt-app-8d46e.firebaseapp.com/apple-app-site-association
it just downloads a GZIP file again.

I really don't know why the Content-Type header is not working.

I tried grabbing the file with curl and I can see on the request
Content-Type: application/json and the file looks fine. When I access through the browser I get the GZIP

To prevent the browser from reading the bytes and automatically inferring the MIME type I even added this to the headers:
X-Content-Type-Options: nosniff but it's still not working.

@stleamist

This comment has been minimized.

Copy link

@stleamist stleamist commented Feb 10, 2020

@asikand It seems like your website is working as expected for me. Could you try this without cache or on another browser?
스크린샷 2020-02-11 오전 7 11 49

@CeccoCQ

This comment has been minimized.

Copy link

@CeccoCQ CeccoCQ commented Apr 16, 2020

Hi guys,
I've a similar issue.

I've the following firestore.json file:

{
  "firestore": {
    "rules": "firestore.rules",
    "indexes": "firestore.indexes.json"
  },
  "functions": {
    "predeploy": ["npm --prefix \"$RESOURCE_DIR\" run lint"]
  },
  "hosting": [
    {
      "target": "site",
      "public": "hosting/dist/site",
      "ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
      "headers": [
        {
          "source": "/.well-known/apple-app-site-association",
          "headers": [
            {
              "key": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        {
          "source": "/apple-app-site-association",
          "headers": [
            {
              "key": "Content-Type",
              "value": "application/json"
            }
          ]
        }
      ],
      "rewrites": [
        {
          "source": "/.well-known/assetlinks.json",
          "destination": "/well-known/assetlinks.json"
        }
      ]
    },
    {
      "target": "admin",
      "public": "hosting/dist/admin/contactless/build",
      "ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
      "headers": [
        {
          "source": "**/*.@(eot|otf|ttf|ttc|woff|font.css)",
          "headers": [
            {
              "key": "Access-Control-Allow-Origin",
              "value": "*"
            }
          ]
        },
        {
          "source": "**/*.@(jpg|jpeg|gif|png)",
          "headers": [
            {
              "key": "Cache-Control",
              "value": "max-age=7200"
            }
          ]
        },
        {
          "source": "404.html",
          "headers": [
            {
              "key": "Cache-Control",
              "value": "max-age=300"
            }
          ]
        }
      ]
    }
  ],
  "storage": {
    "rules": "storage.rules"
  },
  "emulators": {
    "functions": {
      "port": "5001"
    },
    "firestore": {
      "port": "5002"
    },
    "hosting": {
      "port": "5003"
    },
    "pubsub": {
      "port": "5004"
    }
  }
}

And I've into the /hosting/dist/site/.well-known/ the file apple-app-site-association with this json:

{
	"applinks": {
 		"apps": [], 
		"details": [
			{
				"appID": "8XP55WY44Z.com.my.enterprise.contactless",
            	"paths": [ "/events/*" ]
        	}
			{
      	    	"appID": "8XP55WY44Z.com.my.contactless",
            	"paths": [ "/events/*" ]
        	}
		]
		"webcredentials": {
			"apps": [ "8XP55WY44Z.com.my.enterprise.contactless", "8XP55WY44Z.com.my.contactless" ]
		}
	}
}

When I try to validate it with https://branch.io/resources/aasa-validator, I've a empty result (all check passes):

{
    "applinks": {
        "apps": [],
        "details": []
    }
}

I've read that I should have to add a "appAssociation":"NONE" into hosting object in firebase.json file.
But if I add it, I receive a validation error from branch.io/resources/aasa-validator.

So, how can I set a right configuration to handle the aasa functionality?

@CeccoCQ

This comment has been minimized.

Copy link

@CeccoCQ CeccoCQ commented Apr 17, 2020

@stleamist I re-uploaded the files and deployed them to hosting this time without the .json file extension.

Now if I access:
https://fyt-app-8d46e.firebaseapp.com/apple-app-site-association
it just downloads a GZIP file again.

I really don't know why the Content-Type header is not working.

I tried grabbing the file with curl and I can see on the request
Content-Type: application/json and the file looks fine. When I access through the browser I get the GZIP

To prevent the browser from reading the bytes and automatically inferring the MIME type I even added this to the headers:
X-Content-Type-Options: nosniff but it's still not working.

Hi @akisand, how you solved?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.