# Internet-identity Invalid delegation

**URL:** <https://forum.dfinity.org/t/internet-identity-invalid-delegation/5393>\
**Category:** Developers\
**Created:** [June 21, 2021, 6:13am UTC](https://forum.dfinity.org/t/internet-identity-invalid-delegation/5393 "2021-06-21T06:13:06Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![HelloRickey](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/hellorickey/32/2020_2.png) [@HelloRickey](https://forum.dfinity.org/u/HelloRickey)\
**Post date:** [June 21, 2021, 6:13am UTC](https://forum.dfinity.org/t/internet-identity-invalid-delegation/5393/1 "2021-06-21T06:13:06Z")

</div>

Hey guys,

1. I used dfx start to start internet-identity on the local port 8000 and created an account. The login was successful.
2. Start my own project with dfx start on the local port 8001, and set the identityProvider:  
“[http://localhost:8888?canisterId=rwlgt-iiaaa-aaaaa-aaaaa-cai](http://localhost:8888?canisterId=rwlgt-iiaaa-aaaaa-aaaaa-cai)”

```auto
    authClient.login({
      onSuccess: async () => {
        const identity = await authClient.getIdentity();
        const agentOptions = {
          host: "http://localhost:8001",
          identity:identity
        }
        var counter=setActor(agentOptions);
        const response = await counter.getUser(0);
        console.log(response);
      },identityProvider: "http://localhost:8888?canisterId=rwlgt-iiaaa-aaaaa-aaaaa-cai"
    });

```

1. When I call authClient.login, I can log in successfully and get the identity, but when I call the getUser function in canister, it will prompt me a 403 error.  
Code: 403 (Forbidden)  
Body: Failed to authenticate request  
 ![截屏2021-06-21 下午2.08.08](https://us1.discourse-cdn.com/flex023/uploads/dfn/original/2X/c/c387b4bcc4cd595435413946123fad2da504a2cd.png)

Is there any solution? thank.

---

<div class="post-metadata">

**Author:** ![3cL1p5e7](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/3cl1p5e7/32/4649_2.png) [@3cL1p5e7](https://forum.dfinity.org/u/3cL1p5e7)\
**Post date:** [June 21, 2021, 9:00am UTC](https://forum.dfinity.org/t/internet-identity-invalid-delegation/5393/2 "2021-06-21T09:00:00Z")

</div>

What is the implementation of the method `getUser`?  
Try to initialize actor something like as

```auto
// dfx version 0.7.2
import { Actor, HttpAgent, HttpAgentOptions } from '@dfinity/agent';
import { idlFactory as counter_idl, canisterId as counter_id } from 'ic:counter'; // counter canister frontend alias

...

const agentOptions = {
          host: "http://localhost:8001",
          identity: await authClient.getIdentity(),
        };
const agent = new HttpAgent(agentOptions);
const counter = Actor.createActor(counter_idl, { agent, canisterId: counter_id });

const response = await counter.getUser(0);
console.log(response);

```

---

<div class="post-metadata">

**Author:** ![Ori](https://avatars.discourse-cdn.com/v4/letter/o/ecae2f/32.png) [@Ori](https://forum.dfinity.org/u/Ori)\
**Post date:** [June 21, 2021, 9:59am UTC](https://forum.dfinity.org/t/internet-identity-invalid-delegation/5393/3 "2021-06-21T09:59:16Z")

</div>

For LOCAL DEVELOPMENT ONLY your app doesn’t have access to the IC root key, so after creating your agent (in your setActor function) you’ll need to call

`await agent.fetchRootKey()`

before creating the actor.

It’s important that you DO NOT do this in your production deployment, or you’ll open your users up to possible Man in the Middle attacks.

---

<div class="post-metadata">

**Author:** ![HelloRickey](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/hellorickey/32/2020_2.png) [@HelloRickey](https://forum.dfinity.org/u/HelloRickey)\
**Post date:** [June 22, 2021, 6:30am UTC](https://forum.dfinity.org/t/internet-identity-invalid-delegation/5393/4 "2021-06-22T06:30:53Z")

</div>

I added await agent.fetchRootKey() to setActor  
But still report the same error

```auto
export async function setActor(agentOptions) {
  const agent = new HttpAgent(agentOptions)
  await agent.fetchRootKey();
  const counter = Actor.createActor(counter_idl, {
    agent,
    canisterId: counter_id,
  })
  return counter;
}

```

---

<div class="post-metadata">

**Author:** ![Ori](https://avatars.discourse-cdn.com/v4/letter/o/ecae2f/32.png) [@Ori](https://forum.dfinity.org/u/Ori)\
**Post date:** [June 22, 2021, 8:36am UTC](https://forum.dfinity.org/t/internet-identity-invalid-delegation/5393/5 "2021-06-22T08:36:21Z")

</div>

Are you running both Internet Identity and your project on the same replica instance? So just run dfx start once from your project directory, then deploy both your project and the II project to that.

---

<div class="post-metadata">

**Author:** ![HelloRickey](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/hellorickey/32/2020_2.png) [@HelloRickey](https://forum.dfinity.org/u/HelloRickey)\
**Post date:** [June 22, 2021, 9:55am UTC](https://forum.dfinity.org/t/internet-identity-invalid-delegation/5393/6 "2021-06-22T09:55:34Z")

</div>

You are right, I started dfx twice, thank you very much. 😄
