OAuth FFG ok
This commit is contained in:
@@ -1,28 +0,0 @@
|
||||
package org.jeudego.pairgoth.oauth
|
||||
|
||||
class FacebookHelper : OAuthHelper() {
|
||||
override val name: String
|
||||
get() = "facebook"
|
||||
|
||||
override fun getLoginURL(sessionId: String?): String {
|
||||
return "https://www.facebook.com/v14.0/dialog/oauth?" +
|
||||
"client_id=" + clientId +
|
||||
"&redirect_uri=" + redirectURI +
|
||||
"&scope=email" +
|
||||
"&state=" + getState(sessionId!!)
|
||||
}
|
||||
|
||||
override fun getAccessTokenURL(code: String): String? {
|
||||
return "https://graph.facebook.com/v14.0/oauth/access_token?" +
|
||||
"client_id=" + clientId +
|
||||
"&redirect_uri=" + redirectURI +
|
||||
"&client_secret=" + secret +
|
||||
"&code=" + code
|
||||
}
|
||||
|
||||
override fun getUserInfosURL(accessToken: String): String? {
|
||||
return "https://graph.facebook.com/me?" +
|
||||
"field=email" +
|
||||
"&access_token=" + accessToken
|
||||
}
|
||||
}
|
@@ -1,18 +0,0 @@
|
||||
package org.jeudego.pairgoth.oauth
|
||||
|
||||
class GoogleHelper : OAuthHelper() {
|
||||
override val name: String
|
||||
get() = "google"
|
||||
|
||||
override fun getLoginURL(sessionId: String?): String {
|
||||
return ""
|
||||
}
|
||||
|
||||
override fun getAccessTokenURL(code: String): String? {
|
||||
return null
|
||||
}
|
||||
|
||||
override fun getUserInfosURL(accessToken: String): String? {
|
||||
return null
|
||||
}
|
||||
}
|
@@ -1,18 +0,0 @@
|
||||
package org.jeudego.pairgoth.oauth
|
||||
|
||||
class InstagramHelper : OAuthHelper() {
|
||||
override val name: String
|
||||
get() = "instagram"
|
||||
|
||||
override fun getLoginURL(sessionId: String?): String {
|
||||
return ""
|
||||
}
|
||||
|
||||
override fun getAccessTokenURL(code: String): String? {
|
||||
return null
|
||||
}
|
||||
|
||||
override fun getUserInfosURL(accessToken: String): String? {
|
||||
return null
|
||||
}
|
||||
}
|
@@ -1,77 +0,0 @@
|
||||
package org.jeudego.pairgoth.oauth
|
||||
|
||||
// In progress
|
||||
|
||||
import com.republicate.kson.Json
|
||||
import org.jeudego.pairgoth.server.WebappManager
|
||||
//import com.republicate.modality.util.AESCryptograph
|
||||
//import com.republicate.modality.util.Cryptograph
|
||||
import org.apache.commons.codec.binary.Base64
|
||||
import org.slf4j.LoggerFactory
|
||||
import java.io.IOException
|
||||
import java.io.UnsupportedEncodingException
|
||||
import java.net.URLEncoder
|
||||
|
||||
abstract class OAuthHelper {
|
||||
abstract val name: String
|
||||
abstract fun getLoginURL(sessionId: String?): String
|
||||
protected val clientId: String
|
||||
protected get() = WebappManager.getMandatoryProperty("oauth." + name + ".client_id")
|
||||
protected val secret: String
|
||||
protected get() = WebappManager.getMandatoryProperty("oauth." + name + ".secret")
|
||||
protected val redirectURI: String?
|
||||
protected get() = try {
|
||||
val uri: String = WebappManager.getProperty("webapp.external.url") + "/oauth.html"
|
||||
URLEncoder.encode(uri, "UTF-8")
|
||||
} catch (uee: UnsupportedEncodingException) {
|
||||
logger.error("could not encode redirect URI", uee)
|
||||
null
|
||||
}
|
||||
|
||||
protected fun getState(sessionId: String): String {
|
||||
return name + ":" + encrypt(sessionId)
|
||||
}
|
||||
|
||||
fun checkState(state: String, expectedSessionId: String): Boolean {
|
||||
val foundSessionId = decrypt(state)
|
||||
return expectedSessionId == foundSessionId
|
||||
}
|
||||
|
||||
protected abstract fun getAccessTokenURL(code: String): String?
|
||||
@Throws(IOException::class)
|
||||
fun getAccessToken(code: String): String {
|
||||
val json: Json.Object = Json.Object() // TODO - apiClient.get(getAccessTokenURL(code))
|
||||
return json.getString("access_token")!! // ?!
|
||||
}
|
||||
|
||||
protected abstract fun getUserInfosURL(accessToken: String): String?
|
||||
|
||||
@Throws(IOException::class)
|
||||
fun getUserEmail(accessToken: String): String {
|
||||
val json: Json.Object = Json.Object()
|
||||
// TODO
|
||||
// apiClient.get(getUserInfosURL(accessToken))
|
||||
return json.getString("email") ?: throw IOException("could not fetch email")
|
||||
}
|
||||
|
||||
companion object {
|
||||
protected var logger = LoggerFactory.getLogger("oauth")
|
||||
private const val salt = "0efd28fb53cbac42"
|
||||
// private val sessionIdCrypto: Cryptograph = AESCryptograph().apply {
|
||||
// init(salt)
|
||||
// }
|
||||
|
||||
private fun encrypt(input: String): String {
|
||||
return "TODO"
|
||||
// return Base64.encodeBase64URLSafeString(sessionIdCrypto.encrypt(input))
|
||||
}
|
||||
|
||||
private fun decrypt(input: String): String {
|
||||
return "TODO"
|
||||
// return sessionIdCrypto.decrypt(Base64.decodeBase64(input))
|
||||
}
|
||||
|
||||
// TODO
|
||||
// private val apiClient: ApiClient = ApiClient()
|
||||
}
|
||||
}
|
@@ -1,17 +0,0 @@
|
||||
package org.jeudego.pairgoth.oauth
|
||||
|
||||
object OauthHelperFactory {
|
||||
private val facebook: OAuthHelper = FacebookHelper()
|
||||
private val google: OAuthHelper = GoogleHelper()
|
||||
private val instagram: OAuthHelper = InstagramHelper()
|
||||
private val twitter: OAuthHelper = TwitterHelper()
|
||||
fun getHelper(provider: String?): OAuthHelper {
|
||||
return when (provider) {
|
||||
"facebook" -> facebook
|
||||
"google" -> google
|
||||
"instagram" -> instagram
|
||||
"twitter" -> twitter
|
||||
else -> throw RuntimeException("wrong provider")
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,18 +0,0 @@
|
||||
package org.jeudego.pairgoth.oauth
|
||||
|
||||
class TwitterHelper : OAuthHelper() {
|
||||
override val name: String
|
||||
get() = "twitter"
|
||||
|
||||
override fun getLoginURL(sessionId: String?): String {
|
||||
return ""
|
||||
}
|
||||
|
||||
override fun getAccessTokenURL(code: String): String? {
|
||||
return null
|
||||
}
|
||||
|
||||
override fun getUserInfosURL(accessToken: String): String? {
|
||||
return null
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user