(t *testing.T)
| 36 | } |
| 37 | |
| 38 | func TestAuthorizationCodeGrant_Success(t *testing.T) { |
| 39 | mux := http.NewServeMux() |
| 40 | mux.HandleFunc("/2/oauth/token", func(w http.ResponseWriter, r *http.Request) { |
| 41 | assert.Equal(t, http.MethodPost, r.Method) |
| 42 | assert.Equal(t, "application/x-www-form-urlencoded", r.Header.Get("Content-Type")) |
| 43 | |
| 44 | require.NoError(t, r.ParseForm()) |
| 45 | assert.Equal(t, "authorization_code", r.FormValue("grant_type")) |
| 46 | assert.Equal(t, "test-client-id", r.FormValue("client_id")) |
| 47 | assert.Equal(t, "auth-code-123", r.FormValue("code")) |
| 48 | assert.Equal(t, "verifier-xyz", r.FormValue("code_verifier")) |
| 49 | |
| 50 | require.NoError(t, json.NewEncoder(w).Encode(OAuthTokenResponse{ |
| 51 | AccessToken: "access-token-123", |
| 52 | RefreshToken: "refresh-token-456", |
| 53 | TokenType: "Bearer", |
| 54 | ExpiresIn: 7200, |
| 55 | Scope: "scope:test", |
| 56 | User: &User{ |
| 57 | ID: 1, |
| 58 | Email: "user@test.com", |
| 59 | Name: "Test User", |
| 60 | }, |
| 61 | })) |
| 62 | }) |
| 63 | |
| 64 | ts, client := newTestClient(mux) |
| 65 | defer ts.Close() |
| 66 | |
| 67 | resp, err := client.AuthorizationCodeGrant( |
| 68 | "auth-code-123", |
| 69 | "verifier-xyz", |
| 70 | "http://localhost:12345", |
| 71 | ) |
| 72 | require.NoError(t, err) |
| 73 | assert.Equal(t, "access-token-123", resp.AccessToken) |
| 74 | assert.Equal(t, "refresh-token-456", resp.RefreshToken) |
| 75 | assert.Equal(t, "user@test.com", resp.User.Email) |
| 76 | } |
| 77 | |
| 78 | func TestAuthorizationCodeGrant_InvalidGrant(t *testing.T) { |
| 79 | mux := http.NewServeMux() |
nothing calls this directly
no test coverage detected