Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Update FxaClient version to 0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
carolkng authored and csadilek committed Jul 13, 2018
1 parent f2ad615 commit e61a9d7
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
kotlin: '1.2.51',
coroutines: '0.23.4',
supportLibraries: '27.1.1',
fxa: '0.1.2',
fxa: '0.2.0',
jna: '4.5.1',
// Test only:
junit: '4.12',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@ package mozilla.components.service.fxa

class FirefoxAccount(override var rawPointer: RawFxAccount?) : RustObject<RawFxAccount>() {

constructor(config: Config, clientId: String): this(null) {
this.rawPointer = safeSync { e -> FxaClient.INSTANCE.fxa_new(config.consumePointer(), clientId, e) }
constructor(config: Config, clientId: String, redirectUri: String): this(null) {
this.rawPointer = safeSync { e ->
FxaClient.INSTANCE.fxa_new(config.consumePointer(), clientId, redirectUri, e)
}
}

override fun destroy(p: RawFxAccount) {
safeSync { FxaClient.INSTANCE.fxa_free(p) }
}

fun beginOAuthFlow(redirectURI: String, scopes: Array<String>, wantsKeys: Boolean): FxaResult<String> {
fun beginOAuthFlow(scopes: Array<String>, wantsKeys: Boolean): FxaResult<String> {
return safeAsync { e ->
val scope = scopes.joinToString(" ")
val p = FxaClient.INSTANCE.fxa_begin_oauth_flow(validPointer(), redirectURI, scope, wantsKeys, e)
val p = FxaClient.INSTANCE.fxa_begin_oauth_flow(validPointer(), scope, wantsKeys, e)
getAndConsumeString(p) ?: ""
}
}
Expand Down Expand Up @@ -71,10 +73,15 @@ class FirefoxAccount(override var rawPointer: RawFxAccount?) : RustObject<RawFxA
}

companion object {
fun from(config: Config, clientId: String, webChannelResponse: String): FxaResult<FirefoxAccount> {
fun from(
config: Config,
clientId: String,
redirectUri: String,
webChannelResponse: String
): FxaResult<FirefoxAccount> {
return RustObject.safeAsync { e ->
val p = FxaClient.INSTANCE.fxa_from_credentials(config.consumePointer(),
clientId, webChannelResponse, e)
clientId, redirectUri, webChannelResponse, e)
FirefoxAccount(p)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ internal interface FxaClient : Library {
fun fxa_get_release_config(e: Error.ByReference): RawConfig
fun fxa_get_custom_config(content_base: String, e: Error.ByReference): RawConfig

fun fxa_new(config: RawConfig, clientId: String, e: Error.ByReference): RawFxAccount
fun fxa_new(config: RawConfig, clientId: String, redirectUri: String, e: Error.ByReference): RawFxAccount
fun fxa_from_credentials(
config: RawConfig,
clientId: String,
redirectUri: String,
webChannelResponse: String,
e: Error.ByReference
): RawFxAccount
Expand All @@ -43,7 +44,6 @@ internal interface FxaClient : Library {

fun fxa_begin_oauth_flow(
fxa: RawFxAccount,
redirectUri: String,
scopes: String,
wantsKeys: Boolean,
e: Error.ByReference
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ open class MainActivity : AppCompatActivity() {
setContentView(R.layout.activity_main)

Config.custom(CONFIG_URL).whenComplete { value: Config ->
account = FirefoxAccount(value, CLIENT_ID)
account = FirefoxAccount(value, CLIENT_ID, REDIRECT_URL)
}

findViewById<View>(R.id.button).setOnClickListener {
account?.beginOAuthFlow(REDIRECT_URL, scopes, false)?.whenComplete { openTab(it) }
account?.beginOAuthFlow(scopes, false)?.whenComplete { openTab(it) }
}
}

Expand Down

0 comments on commit e61a9d7

Please sign in to comment.