opened
geekofweek
username_0
Make sure you are running the latest version of Home Assistant before reporting an issue.

You should only file an issue if you found a bug. Feature and enhancement requests should go in [the Feature Requests section](https://community.home-assistant.io/c/feature-requests) of our community forum:

**Home Assistant release (`hass --version`):**
0.32.1

**Python release (`python3 --version`):**
Python 3.5.2

**Component/platform:**
iCloud

**Description of problem:**
New iCloud component does not prompt for two factor authentication code anywhere that I can find.  Results in endless loop asking to approve device  

**Expected:**

Should have a place to input 2 factor code

**Problem-relevant `configuration.yaml` entries and steps to reproduce:**
```yaml

  - platform: icloud
    username: {USERNAME}
    password: {PASSWORD}
    account_name: iCloud

```

1.   Start HA
2.  Second device prompts to Approve HA with Code
3.  No Place to input 2 factor Code

**Traceback (if applicable):**
```bash

```

**Additional info:**
iCloud Component Two Factor Code Input Missing
issue
created
marcgetter
username_1
I'm seeing this same issue.
comment
created
olines
username_2
I'm seeing this same issue also.
comment
created
unix0003
username_3
Here as well. iOS 10.1.1, it looks like it has something to do with icloud keychain being on.
comment
created
geekofweek
username_0
Not really sure how keychain would effect it since I get properly prompted to approve the device, just no place to input it in HA.  Seems more like the issue would be with HA as opposed to iCloud.
comment
created
unix0003
username_3
I'm just saying I have two sets of icloud devices, one pair is an iphone 6s with keychain on, and an ipad pro sync'd to it. The other set an iphone 7 with it off. the ipad is the only device being flooded with a code to put into HA.

Are you seeing something different?
comment
created
geekofweek
username_0
My problem is no place to input the code, it'll keep prompting as long as HA (or anything else really) attempts to log into iCloud.
comment
created
terrycarlin
username_4
I get the exact same thing as @geekweek.  I am on the latest stable release of HA. I have 2 Factor authentication enabled on my iCloud account.  My MacBook Air keeps prompting me with a code to enter into the new device (Home Assistant on a Raspberry Pi) when HA starts up.  However, HA has no way for me to enter the code that I have discovered.  Every other iCloud device I have did ask me to enter the code when I registered it onto iCloud for the first time. Entering the code into the HA configuration files won't work as the code changes.  It probably should be entered in the UI.
comment
created
arsaboo
username_5
Just marking @username_6, in case he is not aware of this thread.
comment
created
Bart274
username_6
@username_5 thanks for tagging me, I wasn't award of this thread indeed.

It's not an issue with HA, it's an issue of pyicloud itself. They have implemented a way of detecting 2fa and how to enter the code. Unfortunately, their implementation is wrong. It seems they have implemented 2 step authentication, which is the first version of 2 factor authentication. The real 2 factor implementation isn't implemented yet. 😞
I'm trying to find a work around, otherwise we must wait until it's implemented in pyicloud. 😞
comment
created
geekofweek
username_0
Might want to update the documentation to clarify since this is basically the same problem suffered by the previous component. Since HomeKit + AppleTV requires two factor it might effect a fair share of those wanting to use Home Assistant.
comment
created
Bart274
username_6
@geekoftheweek I'm trying a solution tomorrow, if that works, I need to change the pyicloud repo first and them make a new PR for the device_tracker. I'm waiting until I've tested my solution before I change the documentation.
comment
created
b3nk3
username_7
Is there any change in this? @username_6
comment
created
Bart274
username_6
No not yet, I can't figure this out :(
comment
created
b3nk3
username_7
Bollocks... I thought it's happening because of the customised views... anyway should it not work with a one time password then?

Sent from my iPhone 6S Plus

>
comment
created
stewface
username_8
Just ran into the same issue after activating 2 factor auth to get my apple watch to unlock my mac.. 

Somewhat regretting wasting 45min getting that setup..
comment
created
stewface
username_8
BTW it keep asking me to authorise every few minutes for this one my mac.. :|
comment
created
a5hs
username_9
I've given 

Sent from my iPhone

>
comment
created
a5hs
username_9
My bad, replying from my phone doesn't always go to plan......
I have given this a go myself several times and not been able to resolve. Even had a poke around in the source but can't get this working for an iCloud with 2FA (which is only enabled to allow me to use my Apple TV as a HomeKit hub - my housemates non 2FA enabled iCloud works perfectly)

Stewface, as a workaround for now try using the OwnTracks component . Not perfect but it's what I'm doing until this issue is figured out.
comment
created
stewface
username_8
Thanks for the advice.. no rush on my end.. 

I've gotta setup a new pi3 that came today first and the a start building out the whole setup.. just been experimenting and acquiring sensors ATM 

I did need a reason to setup a mqtt server though;)
comment
created
jldeen
username_10
Hey guys, just wanted to jump in here. I have 2FA working with iCloud and HA, but it only caches the creds for 8 hours. After 8 hours, I get the 2FA prompts again. To input the 2FA code, I simply append the code to the end of my password in the configuration.yaml file. This works. Note: This is how you have to enter a 2FA code on Apple TV Gen2 as well, so I figured it was worth a shot with pyicloud and HA. An iCloud folder is then created in my .homeassistant directory with a cookie created. The cookie claims to expire 2 months from the date created, but 8 hours later, I have to delete and recreate. Not sure if any of this helps, but since it does work for at least 8 hours, is there a way to extend the cached cookie/auth?
comment
created
jdevelvis
username_11
Appending the 2FA code to the end of the password (as in password123456) gives me this error: 

```
17-01-27 15:04:35 pyicloud.base.http: Misdirected Request
17-01-27 15:04:35 homeassistant.components.device_tracker.icloud: Error logging into iCloud Service: ('Invalid email/password combination.', PyiCloudAPIResponseError('Misdirected Request',))
```

```
hass --version
0.36.1
```

```
pip --version pyicloud
pip 1.5.6 from /usr/lib/python3/dist-packages (python 3.4)
```
comment
created
jldeen
username_10
@username_11 After you append the 2FA code to the end of the password the first time you will get that error. Remove the code, and then restart HA, it should authenticate now. Sorry my first post didn't clarify that. Again, it only holds its auth for 8 hours before you have to go through that process again.
comment
created
jdevelvis
username_11
That worked. Thanks! We'll see what happens in 8 hours, haha
comment
created
jdevelvis
username_11
8 hours on the dot, it started asking me to reauthorize, lol. Looks like I'm going to have to wait until it's more thoroughly integrated.
comment
created
jldeen
username_10
@username_11 Yeah, I think it's an HA code issue because the 2FA code does cache, but doesn't hold the auth for the 2 months like it's supposed to.
comment
created
stewface
username_8
Thanks for the work in the looking forward to a solution
comment
created
DevvAndreas
username_12
Is there any fix for this yet? Or still no way to input the 2FA code?
comment
closed
dale3h
username_13
issue
created
dale3h
username_13
Closing this issue as it appears to be fixed by #5984.
comment