Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do apple-app-site-association files work with GitHub Pages (i.e. site.github.io)?

Tags:

I'm trying to setup strong passwords support for an app.

I have a valid JSON file with the correct items:

{
"appLinks": {
    "apps": [],
    "details": [{}]
},
"webcredentials": {
    "apps": [ "<TEAMID>.<BUNDLEID>", "<TEAMID>.<BUNDLEID>" ]
}

}

I've included a ".nojekyll" file to the repo to allow for .folder access. I've validated that with (https://branch.io/resources/aasa-validator).

I've placed the file in /.well-known/apple-app-site-association

I've added the capability to my app and triple checked my TEAM ID and Bundle identifier.

I've also deleted the app from my device and installed and run with and without a debugger attached.

I'm beginning to think GitHub Pages for some reason or another does not support this functionality.

NOTE: my bundleIDs are explicit, meaning instead of "com.company.app", I'm using "app"

Am I right in thinking this?

like image 354
Arin Davoodian Avatar asked Feb 22 '20 23:02

Arin Davoodian


People also ask

Where does Apple-App-site-Association file go?

After you create the apple-app-site-association file, upload it to the root of your HTTPS web server or to the . well-known subdirectory. The file needs to be accessible via HTTPS—without any redirects—at https://<domain>/apple-app-site-association or https://<domain>/.well-known/apple-app-site-association .

How do I host an apple site Association file?

To add the associated domain file to your website, create a file named apple-app-site-association (without an extension). Update the JSON code in the file for the services you support on the domain. For universal links, be sure to list the app identifiers for your domain in the applinks service.

Does Apple-App-site-Association need to be signed?

If your app runs in iOS 9 or later and you use HTTPS to serve the apple-app-site-association file, you can create a plain text file that uses the application/json MIME type and you don't need to sign it.


1 Answers

Nope, I haven't been able to make it work with GitHub Pages alone. If you don't care why you can skip this next bit.

Why GitHub Pages alone can't suffice

As far as I've found out, GitHub Pages alone will not serve up a file at .well-known/apple-app-site-association with Content-Type: application/json. Apple's validation tool wouldn't pass. It requires:

  • .well-known/apple-app-site-association to be served (you can test with curl -v mysite.com/.well-known/apple-app-site-association)
  • It must be served with a Content-Type: application/json header.
  • There cannot be any redirects; i.e. must work without adding -L to your curl command.

Here's the solutions I tried using only GitHub pages that all failed:

  1. First thing I figured out was adding .nojekyll to the top directory of the repo so that .well-known/apple-app-site-association could be served.trying to redirect with a symlink apple-app-site-association to apple-app-site-association.json
    • It was still served as Content-Type: octet-stream
  2. Creating the directory/file structure .well-known/apple-app-site-association/index.json
    • This fails Apple validation because mydomain.com/.well-known/apple-app-site-association redirects to mydomain.com/.well-known/apple-app-site-association/ before returning the correct content and correct content-type header.

Cloudflare/CDN atop GH Pages Solution

However, I was also using Cloudflare to CDN the static pages my GitHub Pages site hosted. You can set this up at the free level and probably should if your page gets any real traffic. You could pick another CDN probably, but it will need custom routing of some kind that supports the content-type/no-redirect stuff Apple demands. In Cloudflare, I was able to effect this for free (unless I got a ton of traffic) with the free tier of their Workers. You can probably adapt the rest of this to your preferred CDN if you use another atop your GitHub Pages site.

From the "Workers" page on Cloudflare, click "Manage Workers" then "Create Worker." Copy/paste and the following JSON as needed (it contains your apple-app-site-association JSON):

addEventListener('fetch', event => {
  event.respondWith(handleRequest(event.request))
})

/**
 * Respond to the request
 * @param {Request} request
 */
async function handleRequest(request) {
  return new Response(JSON.stringify(
  // This is actually your JSON. Because this is JavaScript, you can also add in comments if you like.
{
  "applinks": {
    "details": [
      {
         "appID": "Q94XRK95RT.io.beatscratch.beatscratchFlutterRedux",
         "paths": [ "/app/", "/app"]
      }
    ]
   }
}) + "\n"
, {
  headers: {
      "content-type": "application/json",
    },
  status: 200
  })
}

Note that I had to use the JSON structure from here. This got the above-linked validator to display "Error no apps associated with url" which sounds bad... but things work.

I named the Worker apple-app-site-association but you can name it whatever you like. You can then route my-site.com/.well-known/apple-app-site-association to the Worker.

like image 60
WarDoctor113 Avatar answered Sep 30 '22 19:09

WarDoctor113