Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set default OAuth scope to READ #119

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class RxAppMethods(client: MastodonClient) {
fun createApp(
clientName: String,
redirectUris: String = "urn:ietf:wg:oauth:2.0:oob",
scope: Scope,
scope: Scope = Scope(Scope.Name.READ),
website: String? = null
): Single<AppRegistration> {
return Single.create {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ class AppMethods(private val client: MastodonClient) {
* @param clientName A name for your application
* @param redirectUris Where the user should be redirected after authorization. Defaults to "urn:ietf:wg:oauth:2.0:oob",
* which will display the authorization code to the user instead of redirecting to a web page.
* @param scope Space separated list of scopes. Defaults to all scopes.
* @param scope Space separated list of scopes. Defaults to "read".
* @param website A URL to the homepage of your app, defaults to null.
* @see <a href="https://docs.joinmastodon.org/methods/apps/#create">Mastodon apps API methods #create</a>
*/
@JvmOverloads
fun createApp(
clientName: String,
redirectUris: String = "urn:ietf:wg:oauth:2.0:oob",
scope: Scope = Scope(Scope.Name.ALL),
scope: Scope = Scope(Scope.Name.READ),
website: String? = null
): MastodonRequest<AppRegistration> {
scope.validate()
Expand Down
15 changes: 12 additions & 3 deletions bigbone/src/main/kotlin/social/bigbone/api/method/OAuthMethods.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@ class OAuthMethods(private val client: MastodonClient) {
* or show the authorization code if urn:ietf:wg:oauth:2.0:oob was requested.
* The authorization code can be used while requesting a token to obtain access to user-level methods.
* @param clientId The client ID, obtained during app registration.
* @param scope List of requested OAuth scopes, separated by spaces. Must be a subset of scopes declared during app registration.
* @param scope List of requested OAuth scopes, separated by spaces. Must be a subset of scopes declared during app registration. Defaults to "read".
* @param redirectUri Set a URI to redirect the user to. Defaults to "urn:ietf:wg:oauth:2.0:oob",
* which will display the authorization code to the user instead of redirecting to a web page.
* Must match one of the redirect_uris declared during app registration.
* @see <a href="https://docs.joinmastodon.org/methods/oauth/#authorize">Mastodon oauth API methods #authorize</a>
*/
fun getOAuthUrl(clientId: String, scope: Scope, redirectUri: String = "urn:ietf:wg:oauth:2.0:oob"): String {
fun getOAuthUrl(
clientId: String,
scope: Scope = Scope(Scope.Name.READ),
redirectUri: String = "urn:ietf:wg:oauth:2.0:oob"
): String {
val endpoint = "oauth/authorize"
val params = Parameters()
.append("client_id", clientId)
Expand All @@ -43,6 +47,9 @@ class OAuthMethods(private val client: MastodonClient) {
* Must match one of the redirect_uris declared during app registration.
* @param code A user authorization code, obtained via the URL received from getOAuthUrl()
* @param grantType See Mastodon API documentation for details. Defaults to "authorization_code".
* @param scope List of requested OAuth scopes, separated by spaces (or by pluses, if using query parameters).
* If "code" was provided, then this must be equal to the scope requested from the user. Otherwise, it must be
* a subset of scopes declared during app registration. If not provided, defaults to "read".
* @see <a href="https://docs.joinmastodon.org/methods/oauth/#token">Mastodon oauth API methods #token</a>
*/
@JvmOverloads
Expand All @@ -51,7 +58,8 @@ class OAuthMethods(private val client: MastodonClient) {
clientSecret: String,
redirectUri: String = "urn:ietf:wg:oauth:2.0:oob",
code: String,
grantType: String = "authorization_code"
grantType: String = "authorization_code",
scope: Scope = Scope(Scope.Name.READ)
): MastodonRequest<AccessToken> {
return client.getMastodonRequest(
endpoint = "oauth/token",
Expand All @@ -62,6 +70,7 @@ class OAuthMethods(private val client: MastodonClient) {
append("redirect_uri", redirectUri)
append("code", code)
append("grant_type", grantType)
append("scope", scope.toString())
}
)
}
Expand Down