Loopwise Docs
Concepts

Authorization Code Flow

A detailed walkthrough of the OAuth 2.0 Authorization Code flow with PKCE as implemented by Loopwise.

The Authorization Code flow with PKCE is the only supported OAuth flow in Loopwise. This page explains each step in detail.

Flow diagram

Step-by-step

1. Generate PKCE values

Before starting the flow, generate a random code_verifier (43-128 characters, URL-safe) and compute its SHA-256 hash as the code_challenge:

const codeVerifier = generateRandomString(64);
const codeChallenge = base64url(sha256(codeVerifier));

2. Authorization request

Redirect the user to the authorization endpoint:

GET /oauth/authorize
ParameterRequiredDescription
response_typeYesMust be code
client_idYesYour application's client ID
redirect_uriYesMust match a registered redirect URI
scopeYesSpace-separated list of scopes
stateRecommendedRandom string to prevent CSRF attacks
code_challengeYesPKCE code challenge
code_challenge_methodYesMust be S256

Loopwise handles user authentication. If the user is not logged in, they are shown a login page. After authentication:

  • If the client is a trusted first-party app, authorization is granted automatically (no consent screen)
  • Otherwise, the user sees a consent screen showing the requested scopes
  • The token is automatically scoped to the school where the OAuth application was registered

7. Authorization response

After the user grants consent, Loopwise redirects to your redirect_uri:

https://myapp.com/callback?code=AUTH_CODE&state=YOUR_STATE

Verify that state matches what you sent in step 2.

8-9. Token exchange

Exchange the authorization code for tokens. See Token Endpoints for the full specification.

POST /api/oauth/token
Content-Type: application/x-www-form-urlencoded

grant_type=authorization_code
&code=AUTH_CODE
&redirect_uri=https://myapp.com/callback
&client_id=YOUR_CLIENT_ID
&code_verifier=YOUR_CODE_VERIFIER

10. Use the access token

Include the token in the Authorization header for all API requests:

GET /api/v1/courses
Authorization: Bearer ACCESS_TOKEN

Error responses

If the authorization request fails, Loopwise redirects to your redirect_uri with error parameters:

https://myapp.com/callback?error=access_denied&error_description=The+user+denied+the+request

Common error codes:

ErrorDescription
invalid_requestMissing or invalid parameters
unauthorized_clientClient is not authorized for this grant type
access_deniedUser denied the authorization request
invalid_scopeRequested scope is invalid or exceeds allowed scopes
server_errorInternal server error