Unverified Commit a62ab7fe authored by Lucio Maciel's avatar Lucio Maciel Committed by GitHub

Merge pull request #966 from RocketChat/new/login-with-github

[NEW] Login with GitHub (OAuth).
parents e797d903 30eec406
...@@ -55,7 +55,7 @@ ...@@ -55,7 +55,7 @@
android:theme="@style/AppTheme" /> android:theme="@style/AppTheme" />
<activity <activity
android:name=".webview.gitlab.ui.GitlabWebViewActivity" android:name=".webview.oauth.ui.OauthWebViewActivity"
android:windowSoftInputMode="adjustResize|stateAlwaysHidden" android:windowSoftInputMode="adjustResize|stateAlwaysHidden"
android:theme="@style/AppTheme" /> android:theme="@style/AppTheme" />
......
...@@ -115,6 +115,8 @@ class LoginPresenter @Inject constructor(private val view: LoginView, ...@@ -115,6 +115,8 @@ class LoginPresenter @Inject constructor(private val view: LoginView,
launchUI(strategy) { launchUI(strategy) {
try { try {
val services = client.settingsOauth().services val services = client.settingsOauth().services
val state = "{\"loginStyle\":\"popup\",\"credentialToken\":\"${generateRandomString(40)}\",\"isCordova\":true}".encodeToBase64()
if (services.isNotEmpty()) { if (services.isNotEmpty()) {
var totalSocialAccountsEnabled = 0 var totalSocialAccountsEnabled = 0
...@@ -125,7 +127,6 @@ class LoginPresenter @Inject constructor(private val view: LoginView, ...@@ -125,7 +127,6 @@ class LoginPresenter @Inject constructor(private val view: LoginView,
if (settings.isGithubAuthenticationEnabled()) { if (settings.isGithubAuthenticationEnabled()) {
val clientId = getOauthClientId(services, SERVICE_NAME_GITHUB) val clientId = getOauthClientId(services, SERVICE_NAME_GITHUB)
if (clientId != null) { if (clientId != null) {
val state = generateRandomString(5)
view.setupGithubButtonListener(UrlHelper.getGithubOauthUrl(clientId, state), state) view.setupGithubButtonListener(UrlHelper.getGithubOauthUrl(clientId, state), state)
view.enableLoginByGithub() view.enableLoginByGithub()
totalSocialAccountsEnabled++ totalSocialAccountsEnabled++
...@@ -150,8 +151,6 @@ class LoginPresenter @Inject constructor(private val view: LoginView, ...@@ -150,8 +151,6 @@ class LoginPresenter @Inject constructor(private val view: LoginView,
if (settings.isGitlabAuthenticationEnabled()) { if (settings.isGitlabAuthenticationEnabled()) {
val clientId = getOauthClientId(services, SERVICE_NAME_GILAB) val clientId = getOauthClientId(services, SERVICE_NAME_GILAB)
if (clientId != null) { if (clientId != null) {
// TODO: Improve this code.
val state = "{\"loginStyle\":\"popup\",\"credentialToken\":\"${generateRandomString(40)}\",\"isCordova\":true}".encodeToBase64()
view.setupGitlabButtonListener(UrlHelper.getGitlabOauthUrl(clientId, currentServer, state), state) view.setupGitlabButtonListener(UrlHelper.getGitlabOauthUrl(clientId, currentServer, state), state)
view.enableLoginByGitlab() view.enableLoginByGitlab()
totalSocialAccountsEnabled++ totalSocialAccountsEnabled++
......
...@@ -21,9 +21,9 @@ import chat.rocket.android.helper.TextHelper ...@@ -21,9 +21,9 @@ import chat.rocket.android.helper.TextHelper
import chat.rocket.android.util.extensions.* import chat.rocket.android.util.extensions.*
import chat.rocket.android.webview.cas.ui.INTENT_CAS_TOKEN import chat.rocket.android.webview.cas.ui.INTENT_CAS_TOKEN
import chat.rocket.android.webview.cas.ui.casWebViewIntent import chat.rocket.android.webview.cas.ui.casWebViewIntent
import chat.rocket.android.webview.gitlab.ui.INTENT_OAUTH_CREDENTIAL_SECRET import chat.rocket.android.webview.oauth.ui.INTENT_OAUTH_CREDENTIAL_SECRET
import chat.rocket.android.webview.gitlab.ui.INTENT_OAUTH_CREDENTIAL_TOKEN import chat.rocket.android.webview.oauth.ui.INTENT_OAUTH_CREDENTIAL_TOKEN
import chat.rocket.android.webview.gitlab.ui.gitlabWebViewIntent import chat.rocket.android.webview.oauth.ui.oauthWebViewIntent
import dagger.android.support.AndroidSupportInjection import dagger.android.support.AndroidSupportInjection
import kotlinx.android.synthetic.main.fragment_authentication_log_in.* import kotlinx.android.synthetic.main.fragment_authentication_log_in.*
import javax.inject.Inject import javax.inject.Inject
...@@ -210,9 +210,8 @@ class LoginFragment : Fragment(), LoginView { ...@@ -210,9 +210,8 @@ class LoginFragment : Fragment(), LoginView {
override fun setupGithubButtonListener(githubUrl: String, state: String) { override fun setupGithubButtonListener(githubUrl: String, state: String) {
button_github.setOnClickListener { button_github.setOnClickListener {
// TODO startActivityForResult(context?.oauthWebViewIntent(githubUrl, state), REQUEST_CODE_FOR_OAUTH)
// startActivityForResult(context?.githubWebViewIntent(url, state), REQUEST_CODE_FOR_OAUTH) activity?.overridePendingTransition(R.anim.slide_up, R.anim.hold)
// activity?.overridePendingTransition(R.anim.slide_up, R.anim.hold)
} }
} }
...@@ -238,7 +237,7 @@ class LoginFragment : Fragment(), LoginView { ...@@ -238,7 +237,7 @@ class LoginFragment : Fragment(), LoginView {
override fun setupGitlabButtonListener(gitlabUrl: String, state: String) { override fun setupGitlabButtonListener(gitlabUrl: String, state: String) {
button_gitlab.setOnClickListener { button_gitlab.setOnClickListener {
startActivityForResult(context?.gitlabWebViewIntent(gitlabUrl, state), REQUEST_CODE_FOR_OAUTH) startActivityForResult(context?.oauthWebViewIntent(gitlabUrl, state), REQUEST_CODE_FOR_OAUTH)
activity?.overridePendingTransition(R.anim.slide_up, R.anim.hold) activity?.overridePendingTransition(R.anim.slide_up, R.anim.hold)
} }
} }
......
package chat.rocket.android.webview.gitlab.ui package chat.rocket.android.webview.oauth.ui
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.app.Activity import android.app.Activity
...@@ -16,8 +16,8 @@ import kotlinx.android.synthetic.main.activity_web_view.* ...@@ -16,8 +16,8 @@ import kotlinx.android.synthetic.main.activity_web_view.*
import kotlinx.android.synthetic.main.app_bar.* import kotlinx.android.synthetic.main.app_bar.*
import org.json.JSONObject import org.json.JSONObject
fun Context.gitlabWebViewIntent(webPageUrl: String, state: String): Intent { fun Context.oauthWebViewIntent(webPageUrl: String, state: String): Intent {
return Intent(this, GitlabWebViewActivity::class.java).apply { return Intent(this, OauthWebViewActivity::class.java).apply {
putExtra(INTENT_WEB_PAGE_URL, webPageUrl) putExtra(INTENT_WEB_PAGE_URL, webPageUrl)
putExtra(INTENT_STATE, state) putExtra(INTENT_STATE, state)
} }
...@@ -31,7 +31,7 @@ const val INTENT_OAUTH_CREDENTIAL_TOKEN = "credential_token" ...@@ -31,7 +31,7 @@ const val INTENT_OAUTH_CREDENTIAL_TOKEN = "credential_token"
const val INTENT_OAUTH_CREDENTIAL_SECRET = "credential_secret" const val INTENT_OAUTH_CREDENTIAL_SECRET = "credential_secret"
// Shows a WebView to the user authenticate with your Gitlab credentials. // Shows a WebView to the user authenticate with your Gitlab credentials.
class GitlabWebViewActivity : AppCompatActivity() { class OauthWebViewActivity : AppCompatActivity() {
private lateinit var webPageUrl: String private lateinit var webPageUrl: String
private lateinit var state: String private lateinit var state: String
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment