hstratus-auth: Authenticate with iCloud

[ bsd3, library, network ] [ Propose Tags ] [ Report a vulnerability ]

Authenticate with iCloud using Apple ID credentials stored on disk.

The full sign-in flow — SRP credential exchange followed by any required two-factor (2FA) or legacy two-step (2SA) challenge — is handled by a single login call. On success the library caches a session token for use with other iCloud services.

This library is unofficial and not supported by Apple. It may break without warning if Apple changes their authentication protocol.


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0
Change log ChangeLog.md
Dependencies aeson (>=2.0 && <2.3), aeson-casing (>=0.1 && <0.3), base (>=4.12 && <5), base16-bytestring (>=1.0 && <1.1), base64-bytestring (>=1.0 && <2.1), bytestring (>=0.10.8 && <0.11 || >=0.11.3 && <0.13), case-insensitive (>=1.2 && <1.3), containers (>=0.6 && <0.8), crypto-srp (>=0.1 && <0.2), cryptohash-sha256 (>=0.11 && <0.12), directory (>=1.3 && <1.4), filepath (>=1.4 && <1.6), hstratus-auth, http-client (>=0.5 && <0.8), http-client-tls (>=0.3 && <0.4), http-types (>=0.12.1 && <0.13), optparse-applicative (>=0.18 && <0.19), random (>=1.1 && <1.4), simple-prompt (>=0.2 && <0.3), string-conv (>=0.1 && <0.3), text (>=1.2.3 && <2.2), time (>=1.8 && <1.15), transformers (>=0.5 && <0.7), unix (>=2.7 && <2.9), uuid (>=1.3 && <1.4), web-cookiejar (>=0.1.3 && <0.2), xdg-basedir (>=0.2 && <0.3) [details]
Tested with ghc ==9.2.8, ghc ==9.4.8, ghc ==9.6.7, ghc ==9.8.4, ghc ==9.10.2, ghc ==9.12.1
License BSD-3-Clause
Author
Maintainer Tim Emiola <adetokunbo@emio.la>
Uploaded by adetokunbo at 2026-07-27T11:23:07Z
Category Network
Source repo head: git clone https://github.com/adetokunbo/hstratus.git(hstratus-auth)
Distributions
Downloads 0 total (0 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2026-07-27 [all 1 reports]

Readme for hstratus-auth-0.1.0.0

[back to package description]

hstratus-auth — unofficial authentication for iCloud services

hstratus-auth authenticates with iCloud using Apple ID credentials stored on disk. The full sign-in flow — SRP credential exchange followed by any required two-factor (2FA) or legacy two-step (2SA) challenge — runs automatically, prompting the terminal for verification codes when needed. On success it caches a session token for use with other iCloud services.

Disclaimer — use at your own risk

  • This library is unofficial and not supported by Apple.
  • The iCloud authentication protocol it uses is undocumented and may change without notice.

Usage

The same two steps — saving credentials and authenticating — are available programmatically.

Saving credentials

Write a credentials.json file directly, or call saveCredentials:

import Network.HStratus.Session (Credentials (..), saveCredentials)

saveCreds :: IO ()
saveCreds =
  saveCredentials $ Credentials
    { accountName = "your-apple-id@example.com"
    , password    = "your-password"
    }

Authenticating

Create an Api handle with mkApi, then call login:

import Network.HStratus.Http (mkApi, login, AuthState (..))
import Network.HStratus.Http.Endpoints (Realm (..))

example :: IO ()
example = do
  api <- mkApi Usual  -- or China for mainland China accounts
  result <- login api
  case result of
    Authenticated _session _accountData -> putStrLn "Authenticated!"
    _                                   -> putStrLn "Unexpected result"

Injectable callbacks

Pass your own callbacks to loginWith to replace the interactive prompts — useful in automation or tests. The snippet below shows the code-reader; the phone-selector and device-selector arguments follow the same pattern.

import Network.HStratus.Http (loginWith)
import qualified Data.Text.IO as Text

exampleWith :: Api -> IO AuthState
exampleWith api = loginWith readCode (\_ -> pure Nothing) chooseDevice api
 where
  readCode codeLen = do
    Text.putStrLn $ "Enter the " <> Text.pack (show codeLen) <> "-digit code:"
    Text.getLine
  chooseDevice (d :| _) = pure d

If you already hold a Requires2FA or Requires2SA value from a prior call, resume with completeTwoFactor / completeTwoFactorWith or complete2SA / complete2SAWith.

Reauthentication

The session token expires after a period set by iCloud (approximately two months at the time of writing). When it does, authenticate again to refresh it.

CLI usage

A command-line interface using this behaviour is provided by the hstratus package. Use hstratus auth init and hstratus auth login to save credentials and authenticate.


Apple and the Apple logo are trademarks of Apple Inc., registered in the U.S. and other countries and regions. iCloud is a service mark of Apple Inc., registered in the U.S. and other countries and regions.