Skip to content

Commit f812d0c

Browse files
committed
Add an OAuth2Credentials
1 parent 1127ab4 commit f812d0c

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/main/scala/com/codacy/client/bitbucket/client/Authentication.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ object Authentication {
1515

1616
case class OAuthCredentials(key: String, secretKey: String, token: String, secretToken: String) extends Credentials
1717

18+
case class OAuth2Credentials(accessToken: String) extends Credentials
19+
1820
/**
1921
* Your username and password | app password.
2022
*/
@@ -29,6 +31,7 @@ object Authentication {
2931
def fromCredentials(credentials: Credentials): Authenticator = {
3032
credentials match {
3133
case c: OAuthCredentials => new OAuthAuthenticator(c)
34+
case c: OAuth2Credentials => new OAuth2Authenticator(c)
3235
case c: BasicAuthCredentials => new BasicAuthAuthenticator(c)
3336
}
3437
}
@@ -43,6 +46,10 @@ object Authentication {
4346
def authenticate(req: WSRequest): WSRequest = req.sign(requestSigner)
4447
}
4548

49+
class OAuth2Authenticator(credentials: OAuth2Credentials) extends Authenticator {
50+
override def authenticate(req: WSRequest): WSRequest = req.withQueryString("access_token" -> credentials.accessToken)
51+
}
52+
4653
class BasicAuthAuthenticator(credentials: BasicAuthCredentials) extends Authenticator {
4754
def authenticate(req: WSRequest): WSRequest = req.withAuth(credentials.username, credentials.password, WSAuthScheme.BASIC)
4855
}

0 commit comments

Comments
 (0)