Skip to content

Commit

Permalink
Fix #213
Browse files Browse the repository at this point in the history
  • Loading branch information
mattbdean committed Mar 11, 2018
1 parent 659b5e1 commit 669b80f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
9 changes: 4 additions & 5 deletions lib/src/main/kotlin/net/dean/jraw/oauth/OAuthHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import net.dean.jraw.http.NetworkAdapter
import net.dean.jraw.http.NetworkException
import net.dean.jraw.models.OAuthData
import net.dean.jraw.models.internal.OAuthDataJson
import java.util.*

/**
* This class helps create authenticated RedditClient instances.
Expand Down Expand Up @@ -45,11 +44,11 @@ object OAuthHelper {
@JvmStatic internal fun interactive(http: NetworkAdapter, creds: Credentials,
tokenStore: TokenStore = NoopTokenStore(),
onAuthenticated: (r: RedditClient) -> Unit = {}): StatefulAuthHelper {
return when (creds.authMethod) {
AuthMethod.APP -> StatefulAuthHelper(http, creds, tokenStore, onAuthenticated)
AuthMethod.WEBAPP -> TODO("Web apps aren't supported yet")
else -> throw IllegalArgumentException("AuthMethod ${creds.authMethod} should use automatic authentication")
if (creds.authMethod != AuthMethod.APP && creds.authMethod != AuthMethod.WEBAPP) {
throw IllegalArgumentException("AuthMethod ${creds.authMethod} should use automatic authentication")
}

return StatefulAuthHelper(http, creds, tokenStore, onAuthenticated)
}

@JvmStatic internal fun scriptOAuthData(http: NetworkAdapter, creds: Credentials): OAuthData {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ package net.dean.jraw.test.integration

import com.winterbe.expekt.should
import net.dean.jraw.Endpoint
import net.dean.jraw.oauth.AuthMethod
import net.dean.jraw.oauth.Credentials
import net.dean.jraw.oauth.OAuthHelper
import net.dean.jraw.oauth.StatefulAuthHelper
import net.dean.jraw.test.CredentialsUtil
import net.dean.jraw.test.ensureAuthenticated
import net.dean.jraw.test.expectException
import net.dean.jraw.test.newOkHttpAdapter
import net.dean.jraw.test.*
import org.jetbrains.spek.api.Spek
import org.jetbrains.spek.api.dsl.describe
import org.jetbrains.spek.api.dsl.it
Expand Down Expand Up @@ -62,6 +60,9 @@ class OAuthHelperTest: Spek({
it("should return a fresh StatefulAuthHelper") {
OAuthHelper.interactive(newOkHttpAdapter(), CredentialsUtil.app).authStatus
.should.equal(StatefulAuthHelper.Status.INIT)

OAuthHelper.interactive(newOkHttpAdapter(), createMockCredentials(AuthMethod.WEBAPP)).authStatus
.should.equal(StatefulAuthHelper.Status.INIT)
}

it("should throw an Exception when given a non-installedApp Credentials") {
Expand Down

0 comments on commit 669b80f

Please sign in to comment.