Skip to content
Open
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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ dependencies {
password = "**Your Password**",
logging = true
)

//With Access or OAUTH2 Token
val client = ZammadClient(
baseurl = "**Zammad Url (https:// included)**",
token = "**Your Http Access or OAUTH2 Token**",
authType = "**Auth Type from utils/Constants **",
logging = true
)
```

### Use the Client.
Expand Down
11 changes: 9 additions & 2 deletions lib/src/main/java/com/kirkbushman/zammad/ZammadClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.util.Log
import com.kirkbushman.zammad.models.*
import com.kirkbushman.zammad.models.compat.TicketArticleCompat
import com.kirkbushman.zammad.models.compat.TicketCompat
import com.kirkbushman.zammad.utils.Constants
import com.kirkbushman.zammad.utils.Utils.buildRetrofit
import retrofit2.Retrofit

Expand All @@ -13,10 +14,12 @@ class ZammadClient(
baseUrl: String,

private val auth: String,
private val authType: Int,
private val logging: Boolean
) {

constructor(baseUrl: String, username: String, password: String, logging: Boolean) : this(baseUrl, "$username:$password", logging)
constructor(baseUrl: String, username: String, password: String, logging: Boolean) : this(baseUrl, "$username:$password",
Constants.AUTH_TYPE_USERNAME_PASSWORD, logging)

companion object {

Expand Down Expand Up @@ -1285,6 +1288,10 @@ class ZammadClient(
}

private fun getHeaderMap(): HashMap<String, String> {
return hashMapOf("Authorization" to "Basic ".plus(String(Base64.encode(auth.toByteArray(), Base64.NO_WRAP))))
return when (authType) {
Constants.AUTH_TYPE_ACCESS_TOKEN -> hashMapOf("Authorization" to "Token token=".plus(auth))
Constants.AUTH_TYPE_OAUTH2 -> hashMapOf("Authorization" to "Bearer ".plus(auth))
else -> hashMapOf("Authorization" to "Basic ".plus(String(Base64.encode(auth.toByteArray(), Base64.NO_WRAP))))
}
}
}
7 changes: 7 additions & 0 deletions lib/src/main/java/com/kirkbushman/zammad/utils/Constants.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.kirkbushman.zammad.utils

object Constants {
const val AUTH_TYPE_USERNAME_PASSWORD = 0
const val AUTH_TYPE_ACCESS_TOKEN = 1
const val AUTH_TYPE_OAUTH2 = 2
}