Skip to content

Commit

Permalink
Remove newAuth as it has been discontinued
Browse files Browse the repository at this point in the history
  • Loading branch information
sloshy committed Jan 13, 2021
1 parent bafbcd1 commit e66ffa7
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 121 deletions.
23 changes: 0 additions & 23 deletions github4s/src/main/scala/github4s/algebras/Auth.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,6 @@ import github4s.domain._

trait Auth[F[_]] {

/**
* Call to request a new authorization given a basic authentication, the returned object Authorization includes an
* access token
*
* @param username the username of the user
* @param password the password of the user
* @param scopes attached to the token
* @param note to remind you what the OAuth token is for
* @param client_id the 20 character OAuth app client key for which to create the token
* @param client_secret the 40 character OAuth app client secret for which to create the token
* @param headers optional user headers to include in the request
* @return GHResponse[Authorization] new authorization with access_token
*/
def newAuth(
username: String,
password: String,
scopes: List[String],
note: String,
client_id: String,
client_secret: String,
headers: Map[String, String] = Map()
): F[GHResponse[Authorization]]

/**
* Generates the authorize url with a random state, both are returned within Authorize object
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,6 @@ class AuthInterpreter[F[_]: Applicative](implicit
client: HttpClient[F]
) extends Auth[F] {

override def newAuth(
username: String,
password: String,
scopes: List[String],
note: String,
client_id: String,
client_secret: String,
headers: Map[String, String]
): F[GHResponse[Authorization]] =
client.postAuth[NewAuthRequest, Authorization](
method = "authorizations",
headers =
Map("Authorization" -> s"Basic ${s"$username:$password".getBytes.toBase64}") ++ headers,
data = NewAuthRequest(scopes, note, client_id, client_secret)
)

override def authorizeUrl(
client_id: String,
redirect_uri: String,
Expand Down
20 changes: 0 additions & 20 deletions github4s/src/test/scala/github4s/integration/AuthSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,6 @@ import github4s.utils.{BaseIntegrationSpec, Integration}

trait AuthSpec extends BaseIntegrationSpec {

"Auth >> NewAuth" should "return error on Left when invalid credential is provided" taggedAs Integration in {
val response = clientResource
.use { client =>
Github[IO](client).auth
.newAuth(
validUsername,
invalidPassword,
validScopes,
validNote,
validClientId,
invalidClientSecret,
headerUserAgent
)
}
.unsafeRunSync()

testIsLeft[GHError.UnauthorizedError, Authorization](response)
response.statusCode shouldBe unauthorizedStatusCode
}

"Auth >> AuthorizeUrl" should "return the expected URL for valid username" taggedAs Integration in {
val response = clientResource
.use { client =>
Expand Down
29 changes: 0 additions & 29 deletions github4s/src/test/scala/github4s/unit/AuthSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,35 +26,6 @@ import github4s.interpreters.AuthInterpreter

class AuthSpec extends BaseSpec {

"Auth.newAuth" should "call to httpClient.postAuth with the right parameters" in {

val response: IO[GHResponse[Authorization]] =
IO(GHResponse(authorization.asRight, okStatusCode, Map.empty))

val request = NewAuthRequest(validScopes, validNote, validClientId, invalidClientSecret)

implicit val httpClientMock = httpClientMockPostAuth[NewAuthRequest, Authorization](
url = "authorizations",
headers =
Map("Authorization" -> s"Basic ${s"rafaparadela:invalidPassword".getBytes.toBase64}"),
req = request,
response = response
)

val auth = new AuthInterpreter[IO]

auth.newAuth(
validUsername,
invalidPassword,
validScopes,
validNote,
validClientId,
invalidClientSecret,
headerUserAgent
)

}

"Auth.getAccessToken" should "call to httpClient.postOAuth with the right parameters" in {

val response: IO[GHResponse[OAuthToken]] =
Expand Down
37 changes: 4 additions & 33 deletions microsite/docs/auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ permalink: auth
Github4s supports the [Authorization API](https://developer.github.com/v3/oauth_authorizations/). As a result,
with Github4s, you can:

- [Create a new authorization token](#create-a-new-authorization-token)
- [Authorize a url](#authorize-a-url)
- [Get an access token](#get-an-access-token)

Previously, you were able to use the authorizations API with a username and password.
This has been removed from the GitHub API as of November 13, 2020, and has also been removed from Github4s.
For more information, [see this documentation notice](https://docs.github.com/en/free-pro-team@latest/rest/overview/other-authentication-methods#via-username-and-password).

The following examples assume the following code:

```scala mdoc:silent
Expand All @@ -37,38 +40,6 @@ val gh = Github[IO](httpClient, None)
**NOTE**: Above you can see `Github(httpClient, None)`. This is due to the fact that if you are
authenticating for the first time you don't have any access token yet.

### Create a new authorization token

Used to request a new auth token given basic authentication.

You can create a new authorization token using `newAuth`; it takes as arguments:

- basic authentication for the token holder (`username` and `password`).
- `scopes`: attached to the token, for more information see [the scopes doc](https://developer.github.com/v3/oauth/#scopes).
- `note`: to remind you what the OAuth token is for.
- `client_id`: the 20 character OAuth app client key for which to create the token.
- `client_secret`: the 40 character OAuth app client secret for which to create the token.

```scala mdoc:compile-only
val newAuth = gh.auth.newAuth(
"rafaparadela",
"invalidPassword",
List("public_repo"),
"New access token",
"e8e39175648c9db8c280",
"1234567890")
val response = newAuth.unsafeRunSync()
response.result match {
case Left(e) => println(s"Something went wrong: ${e.getMessage}")
case Right(r) => println(r)
}
```

The `result` on the right is the created [Authorization][auth-scala] including the created token.

See [the API doc](https://developer.github.com/v3/oauth_authorizations/#create-a-new-authorization) for full reference.


### Authorize a url

Generates an authorize url with a random state, both are returned within an [Authorize][auth-scala].
Expand Down

0 comments on commit e66ffa7

Please sign in to comment.