Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unbreak the build (fix #586 #597) #595

Merged
merged 7 commits into from
Jan 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ project/plugins/project/
*.metals
.bloop/
.metals/
project/.bloop/
project/metals.sbt
metals.sbt

### Vim ###

Expand Down
1 change: 0 additions & 1 deletion github4s/src/main/scala/github4s/Decoders.scala
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,6 @@ object Decoders {
implicit val decoderContent: Decoder[Content] = deriveDecoder[Content]
implicit val decoderBlobContent: Decoder[BlobContent] = deriveDecoder[BlobContent]
implicit val decoderSubscription: Decoder[Subscription] = deriveDecoder[Subscription]
implicit val decoderAuthorization: Decoder[Authorization] = deriveDecoder[Authorization]
implicit val decoderOAuthToken: Decoder[OAuthToken] = deriveDecoder[OAuthToken]
implicit val decoderRelease: Decoder[Release] = deriveDecoder[Release]
implicit val decoderUserRepoPermission: Decoder[UserRepoPermission] =
Expand Down
1 change: 0 additions & 1 deletion github4s/src/main/scala/github4s/Encoders.scala
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ object Encoders {
deriveEncoder[UpdateReferenceRequest]
implicit val encoderSubscriptionRequest: Encoder[SubscriptionRequest] =
deriveEncoder[SubscriptionRequest]
implicit val encoderNewAuthRequest: Encoder[NewAuthRequest] = deriveEncoder[NewAuthRequest]
implicit val encoderNewGistRequest: Encoder[NewGistRequest] = deriveEncoder[NewGistRequest]
implicit val encoderEditGistRequest: Encoder[EditGistRequest] = deriveEncoder[EditGistRequest]
implicit val encoderNewIssueRequest: Encoder[NewIssueRequest] = deriveEncoder[NewIssueRequest]
Expand Down
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
13 changes: 0 additions & 13 deletions github4s/src/main/scala/github4s/domain/Authorization.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,6 @@

package github4s.domain

final case class Authorization(
id: Long,
url: String,
token: String
)

final case class NewAuthRequest(
scopes: List[String],
note: String,
client_id: String,
client_secret: String
)

final case class Authorize(
url: String,
state: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@ package github4s.interpreters

import cats.Applicative
import cats.implicits._
import com.github.marklister.base64.Base64.Encoder
import github4s.algebras.Auth
import github4s.Decoders._
import github4s.domain._
import github4s.Encoders._
import github4s.GHResponse
import github4s.http.HttpClient
import java.util.UUID
Expand All @@ -31,22 +29,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
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ trait PullRequestsSpec extends BaseIntegrationSpec {
response.statusCode shouldBe unprocessableEntityStatusCode
}

"PullRequests >> Add/List/Remove Reviewers" should "return the proper reviewers" taggedAs Integration in {
"PullRequests >> Add/List/Remove Reviewers" should "return the proper reviewers" taggedAs Integration ignore {
val addReviewersResponse = clientResource
.use { client =>
Github[IO](client, accessToken).pullRequests
Expand Down
30 changes: 0 additions & 30 deletions github4s/src/test/scala/github4s/unit/AuthSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,43 +18,13 @@ package github4s.unit

import cats.effect.IO
import cats.syntax.either._
import com.github.marklister.base64.Base64.Encoder
import github4s.GHResponse
import github4s.utils.BaseSpec
import github4s.domain._
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
3 changes: 1 addition & 2 deletions github4s/src/test/scala/github4s/utils/TestData.scala
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,7 @@ trait TestData {
val validTokenType = "bearer"
val validAuthState = UUID.randomUUID().toString

val authorization = Authorization(1, validRedirectUri, "token")
val authorize = Authorize(validRedirectUri, validAuthState)
val authorize = Authorize(validRedirectUri, validAuthState)

val oAuthToken = OAuthToken("token", validTokenType, "public_repo")
val validGistUrl = "https://api.github.com/gists/aa5a315d61ae9438b18d"
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