composer/composer — pull request #1238 by 1stvamp (2012-10-19 23:40:44+00:00)
Title: Fix Github OAuth2 token fetching

This fix is 2 fold:

1. Use `read -r` rather than the current `read` shell builtin to take a password from the user on the CLI, th `-r` is the raw option which means backslashes (`\`) aren't interpreted as escape characters, so `\` is a literal `\`, otherwise they are nommed or double slashes become single ones etc.

2. Disable redirects by when fetching URLs with `file_get_contents` **unless** the HTTP status line is `301` (perma redirect) or `302` (temp redirect), or the context option is re-enabled explicitly in the options array passed to the `RemoteFilesystem`, using the `max_redirects` or `follow_location` options, see http://php.net/manual/en/context.http.php.

This second fix is because Github's response to a created token is a `201` response with a `Location` header pointing to the canonical URI for the token itself, and with default HTTP context settings `file_get_contents` follows this location field erroneously ending with a `401` at the token URI itself (because the authentication details weren't maintain after the redirect) and Composer reporting "Invalid credentials.".