-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add LoginActivity and OAuth-related files and settings
- Loading branch information
Showing
6 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
app/src/main/java/org/ageage/eggplant/common/oauth/HatenaOAuthApi.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.ageage.eggplant.common.oauth | ||
|
||
import com.github.scribejava.core.builder.api.DefaultApi10a | ||
|
||
class HatenaOAuthApi : DefaultApi10a() { | ||
override fun getRequestTokenEndpoint(): String { | ||
return "https://www.hatena.com/oauth/initiate?scope=read_public,write_public" | ||
} | ||
|
||
override fun getAuthorizationBaseUrl(): String { | ||
return "https://www.hatena.ne.jp/touch/oauth/authorize" | ||
} | ||
|
||
override fun getAccessTokenEndpoint(): String { | ||
return "https://www.hatena.com/oauth/token" | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
app/src/main/java/org/ageage/eggplant/common/oauth/HatenaOAuthManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package org.ageage.eggplant.common.oauth | ||
|
||
import com.github.scribejava.core.builder.ServiceBuilder | ||
import com.github.scribejava.core.model.OAuth1RequestToken | ||
import com.github.scribejava.core.oauth.OAuth10aService | ||
import io.reactivex.Single | ||
|
||
private const val CALLBACK = "https://ageage.org" | ||
|
||
class HatenaOAuthManager( | ||
private val consumerKey: String, | ||
private val consumerSecret: String | ||
) { | ||
|
||
private var service: OAuth10aService? = null | ||
private var requestToken: OAuth1RequestToken? = null | ||
|
||
fun fetchAuthorizationUrl(): Single<String?> { | ||
return Single.create { | ||
service = ServiceBuilder(consumerKey) | ||
.apiSecret(consumerSecret) | ||
.callback(CALLBACK) | ||
.build(HatenaOAuthApi()) | ||
|
||
requestToken = service?.requestToken | ||
service?.getAuthorizationUrl(requestToken)?.let { token -> | ||
it.onSuccess(token) | ||
} | ||
} | ||
} | ||
|
||
fun fetchAccessToken(oauthVerifier: String): Single<String> { | ||
return Single.create { | ||
service?.let { oAuthService -> | ||
val accessToken = | ||
oAuthService.getAccessToken(requestToken, oauthVerifier) | ||
it.onSuccess(accessToken.rawResponse) | ||
} | ||
} | ||
} | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
app/src/main/java/org/ageage/eggplant/login/LoginActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.ageage.eggplant.login | ||
|
||
import android.os.Bundle | ||
import androidx.appcompat.app.AppCompatActivity | ||
import org.ageage.eggplant.R | ||
|
||
class LoginActivity : AppCompatActivity() { | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_login) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context=".login.LoginActivity"> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> |