Oauth for native applications (with PKCE) ┌─┐ ║"│ └┬┘ ┌┼┐ │ ┌┴┐ ┌──────────────┐ ┌──────────┐ ┌───────────┐ ┌───┐ User/User-Agent │Mobile Browser│ │mobile app│ │Auth server│ │Api│ (mobile device) └───────┬──────┘ └─────┬────┘ └─────┬─────┘ └─┬─┘ │ │ I'd like to use this app │ │ │ │──────────────────────────────────────────────────────────────────────────────────────────────>│ │ │ │ │ │ │ │ │ │ │────┐ │ │ │ │ │ │ I'll generate a secret and hash it (PKCE) │ │ │ │ │<───┘ │ │ │ │ │ │ │ │ │open auth server url with this hash as query string (front-channel) │ │ │ │ │/auth?response_type={code}& │ │ │ │ │client_id={client_id}& │ │ │ │ │redirect_uri={redirect_uri}& │ │ │ │ │scope={scope}& │ │ │ │ │state={random_value}& │ │ │ │ │code_challenge={hash_rand_str}& │ │ │ │ │code_challenge_method=S256 │ │ │ │ │<───────────────────────────────────────────────────────────────────│ │ │ │ │ │ │ │ │ │ grant me access, here's the hash (front-channel) │ │ │ │───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────>│ │ │ │ │ │ │ │ │ here's a temporary code, exchange for token (front-channel) │ │ │ │<───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────│ │ │ │ │ │ │ │ │ here's a temporary code │ │ │ │ │ redirect?code={temp_code}&state={state} │ │ │ │ │───────────────────────────────────────────────────────────────────>│ │ │ │ │ │ │ │ │ │ │here's the code and secret unhashed, give me token │ │ │ │ │POST /token form_encoded │ │ │ │ │grant_type=authorization_code& │ │ │ │ │code={temp_code}& │ │ │ │ │redirect_uri={redirect_uri}& │ │ │ │ │code_verifier={rand_str_unhashed}& │ │ │ │ │client_id={client_id} │ │ │ │ │──────────────────────────────────────────────────>│ │ │ │ │ │ │ │ │ │ │────┐ │ │ │ │ │ │ verify hash of the secret │ │ │ │ │<───┘ │ │ │ │ │ │ │ │ │ here's the token │ │ │ │ │<──────────────────────────────────────────────────│ │ │ │ │ │ │ │ │ │ give me data with this token │ │ │ │───────────────────────────────────────────────────────────────────────────────────>│ User/User-Agent ┌───────┴──────┐ ┌─────┴────┐ ┌─────┴─────┐ ┌─┴─┐ (mobil┌─┐evice) │Mobile Browser│ │mobile app│ │Auth server│ │Api│ ║"│ └──────────────┘ └──────────┘ └───────────┘ └───┘ └┬┘ ┌┼┐ │ ┌┴┐