Skip to content
Tutorials Center
My learning

Topics

Lesson 12 of 38 ยท Identity and Access

Authentication, MFA and Federation

Understand strong cloud authentication: password hygiene, MFA types, phishing-resistant keys, single sign-on with SAML and OpenID Connect, and a runnable TOTP code generator.

Authentication is the front door of every cloud account. Attackers know that guessing, phishing or buying a valid credential is far easier than breaking encryption, so strong authentication is the first line of defense. This lesson covers what makes authentication strong, how multi-factor methods differ, and how federation lets one trusted identity provider sign people in to many services.

Factors of authentication

There are three classic kinds of factor:

  • Something you know: a password or PIN.
  • Something you have: a phone, a hardware security key, a smart card.
  • Something you are: a fingerprint or face, usually checked by your own device.

Multi-factor authentication (MFA) combines at least two different kinds. A password plus a security question is still one factor (both are knowledge).

Not all MFA is equal

MFA, weakest to strongest

SMS codes Better than nothing
App codes (TOTP) Better, still phishable
Push approval Beware of fatigue
Security keys, passkeys Phishing-resistant

Use phishing-resistant methods for admins first.

1 / 2
  • SMS or voice codes can be intercepted or redirected by SIM swapping. Use only if nothing better is available.
  • Time-based one-time passwords (TOTP) from an authenticator app are a solid baseline, but a convincing fake login page can trick a person into typing the code.
  • Push notifications are convenient, but attackers send repeated prompts hoping the user taps "approve" out of annoyance (MFA fatigue). Number matching and context in the prompt help.
  • FIDO2 / WebAuthn security keys and passkeys use public-key cryptography bound to the real website address, so a fake site simply cannot obtain a valid response. This is the strongest option and should protect administrators and the account owner first.

Password hygiene

  • Prefer long passphrases and a password manager over complexity rules.
  • Check new passwords against lists of known-leaked passwords.
  • Never reuse passwords between systems.
  • Do not force frequent rotation without evidence of compromise; it encourages weak patterns.
  • Where passwords remain, rate-limit attempts and alert on bursts of failures.

How TOTP works

A TOTP code is computed from a shared secret and the current time. Both your authenticator app and the server know the secret (set up once by scanning a QR code). Every 30 seconds both compute the same short number from the secret and the time step, using HMAC, so nothing secret travels at login time. The codes are described by an open standard (RFC 6238), built on HOTP (RFC 4226).

The program below implements it with only the Python standard library. It uses a fixed demo secret and a fixed timestamp so the output is repeatable. Never reuse this demo secret anywhere real.

Python Generate and verify a TOTP code

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The first two lines check our implementation against the official published test values (755224 and 287082). A code is accepted for a short window to tolerate clock drift, and rejected after it expires. Use hmac.compare_digest to compare codes so timing does not leak information.

Federation and single sign-on

Instead of creating separate usernames in every cloud account and SaaS app, you connect them to a central identity provider (IdP). Users sign in once at the IdP, with strong MFA, and the IdP vouches for them to other services (the relying parties or service providers).

  • SAML 2.0 is an XML-based standard common in enterprise single sign-on to consoles and SaaS apps. The IdP sends a signed assertion about the user to the service.
  • OpenID Connect (OIDC) adds an identity layer on top of OAuth 2.0 and uses signed JSON Web Tokens (JWT). It is the common choice for modern web, mobile and workload federation.
  • OAuth 2.0 is a framework for delegated authorization (a token that lets an app call an API on your behalf), not authentication by itself.
  • SCIM automates creating and removing user accounts from the IdP.
sequenceDiagram
    participant U as User
    participant S as Cloud console (service)
    participant I as Identity provider
    U->>S: Open console
    S->>U: Redirect to identity provider
    U->>I: Sign in with MFA
    I->>U: Signed assertion or token
    U->>S: Present assertion
    S->>S: Verify signature, map to role
    S->>U: Session with temporary credentials

The service never sees the password: it trusts a signed statement from the provider.

Benefits: one place to enforce MFA and conditional access, instant offboarding, central audit logs, and no long-lived cloud passwords. Risks: the IdP becomes a crown jewel, so protect it as your most critical system.

Checking a token the safe way

When your code receives a JWT, validate it fully: verify the signature with the issuer's published keys, check the issuer and audience match your expectations, check it has not expired, and reject the none algorithm. Never trust claims in a token you have not verified.

Production advice. Use a well-maintained library for token verification and for TOTP. The code above is for learning how the mechanism works.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Which authentication method is the most resistant to phishing?

    They bind the response to the real site address, so fake sites cannot obtain a valid response.
  2. 2. How does a TOTP code stay in sync between your phone and the server?

    HMAC of the time step with the shared secret gives the same code on both sides.
  3. 3. What is MFA fatigue?

    Repeated approval prompts can wear users down; number matching and context reduce the risk.
  4. 4. In SSO, what does the service trust?

    The service verifies the signature and claims from the identity provider instead of handling the password.
  5. 5. What is OAuth 2.0 primarily for?

    OAuth issues tokens that let an app act on a user's behalf; OpenID Connect adds authentication on top.

Summary

  • Use at least two kinds of factors; prefer phishing-resistant security keys and passkeys, especially for administrators.
  • TOTP derives codes from a shared secret and time using HMAC; verify with a small window and constant-time comparison.
  • Federation through SAML or OIDC lets one hardened identity provider authenticate users for many services and simplifies offboarding.
  • Validate tokens completely: signature, issuer, audience and expiry.

Next: Roles, Temporary Credentials and Secrets