Skip to content

Commit

Permalink
Merge pull request #3394 from dfinity/apply-feedback
Browse files Browse the repository at this point in the history
Apply feedback: Fix Motoko example + Revise II alternative origins
  • Loading branch information
jessiemongeon1 authored Aug 27, 2024
2 parents c346ece + 7d107bf commit 7e6e4d0
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ If your application has reached the stage where you want to change domain names,

You may need this guide if you are doing any of the following:

- Moving from `<canister-id>.icp0.io` to a custom domain.
- Moving from `<canister-id>.icp0.io` to a [custom domain](/docs/current/developer-docs/web-apps/custom-domains/using-custom-domains/).
- Asking users to login at `/login` instead of `/`.
- Supporting users using `raw.icp0.io`.
- Configuring multiple apps in your organization to use the same principals.
Expand All @@ -27,20 +27,20 @@ Currently, a maximum of **10** alternative origins can be listed.

II will only follow this specification when the origin configuring these alternatives is hosted on a canister using **certified assets**.

For more information, see the [Internet Identity specification](https://github.com/dfinity/internet-identity/blob/main/docs/ii-spec.md#alternative-frontend-origins).
For more information, see the [Internet Identity specification](/docs/current/references/ii-spec/#alternative-frontend-origins).

## Configuring alternative origins

For this example, you will have two domains, **A** and **B**. **A** will be the canonical origin, and **B** will be the alternative domain. To help illustrate this model, consider this website, which is hosted both at `https://yourcustomdomain.com` and `https://www.yourdomain.com`.

In this example, **A** would be `https://yourcustomdomain.com`.

**B** would be the alternative origin, or `https://www.yourdomain.com`.

:::info
Your custom domains must be registered with the boundary nodes.
For production use cases, domain **A** would use a domain on ICP, such as `ic0.app` or `icp0.io`.
:::

**B** would be the alternative origin, or `https://www.yourdomain.com`.

### Listing origins

On origin **A**, you will need to provide a file that tells Internet Identity that **B** is a valid alternative origin. You'll be placing the config files in `src/assets` directory of your frontend canister. If your frontend canister is currently configured to deploy assets from a `dist` folder, make sure to update the `sources` for your canister to include both:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,38 +32,59 @@ The following example returns 'Hello, World!' in the body at the `/hello` endpoi
<TabItem value="motoko" label="Motoko">

```motoko
import Buffer "mo:base/Buffer";
import HashMap = "mo:base/HashMap";
import Blob = "mo:base/Blob";
import Text "mo:base/Text";
import Option "mo:base/Option";
actor {
public type HttpRequest = {
body: Blob;
headers: [HeaderField];
method: Text;
url: Text;
};
type HeaderField = (Text, Text);
public type ChunkId = Nat;
public type SetAssetContentArguments = {
chunk_ids: [ChunkId];
content_encoding: Text;
key: Key;
sha256: ?Blob;
};
public type Path = Text;
public type Key = Text;
type HttpResponse = {
status_code: Nat16;
headers: [HeaderField];
body: Blob;
};
public type HttpResponse = {
body: Blob;
headers: [HeaderField];
status_code: Nat16;
};
type HttpRequest = {
method: Text;
url: Text;
headers: [HeaderField];
body: Blob;
};
public type HeaderField = (Text, Text);
public query func http_request(req: HttpRequest): async (HttpResponse) {
let path = removeQuery(req.url);
if(path == "/hello") {
return {
status_code = 200,
headers = [],
body = Buffer.from('Hello, World!'),
};
private func removeQuery(str: Text): Text {
return Option.unwrap(Text.split(str, #char '?').next());
};
public query func http_request(req: HttpRequest): async (HttpResponse) {
let path = removeQuery(req.url);
if(path == "/hello") {
return {
body = Text.encodeUtf8("root page :" # path);
headers = [];
status_code = 200;
};
};
return {
body = Text.encodeUtf8("404 Not found :");
body = Text.encodeUtf8("404 Not found :" # path);
headers = [];
status_code = 404;
};
};
};
}
```

</TabItem>
Expand Down

0 comments on commit 7e6e4d0

Please sign in to comment.