Skip to content

Commit

Permalink
MBL-1213: Stop sending token as query param for V1, send the token as…
Browse files Browse the repository at this point in the history
… basic auth header (#1958)
  • Loading branch information
Arkariang authored Feb 28, 2024
1 parent ad17e5f commit 925af00
Show file tree
Hide file tree
Showing 24 changed files with 325 additions and 266 deletions.
12 changes: 10 additions & 2 deletions app/src/main/java/com/kickstarter/libs/CurrentUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,19 @@ public String getAccessToken() {
}

@Override
public void login(final @NonNull User newUser, final @NonNull String accessToken) {
public void login(final @NonNull User newUser) {
Timber.d("Login user %s", newUser.name());
this.user.onNext(newUser);
}

@Override
public void setToken(final @NonNull String accessToken) {
// - Clean previous token in case there is any
this.accessTokenPreference.delete();
this.deviceRegistrar.unregisterDevice();

// - Register new token
this.accessTokenPreference.set(accessToken);
this.user.onNext(newUser);
this.deviceRegistrar.registerDevice();
}

Expand Down
12 changes: 10 additions & 2 deletions app/src/main/java/com/kickstarter/libs/CurrentUserType.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,19 @@

public abstract class CurrentUserType {

/***
* Persist a new token,
* - retrieved form #exchange endpoint {/v1/oauth/authorizations/exchange}
* - retrieved from Facebook login
* - retrieved from endpoint {/xauth/access_token} soon to be deprecated
*/
public abstract void setToken(final @NonNull String accessToken);

/**
* Call when a user has logged in. The implementation of `CurrentUserType` is responsible
* for persisting the user and access token.
* for persisting the user.
*/
public abstract void login(final @NonNull User newUser, final @NonNull String accessToken);
public abstract void login(final @NonNull User newUser);

/**
* Call when a user should be logged out.
Expand Down
22 changes: 18 additions & 4 deletions app/src/main/java/com/kickstarter/libs/CurrentUserV2.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,17 @@ import io.reactivex.subjects.BehaviorSubject
import timber.log.Timber

abstract class CurrentUserTypeV2 {

/***
* Persist a new token, retrieved form #exchange endpoint {/v1/oauth/authorizations/exchange}
*/
abstract fun setToken(accessToken: String)

/**
* Call when a user has logged in. The implementation of `CurrentUserType` is responsible
* for persisting the user and access token.
* for persisting the user.
*/
abstract fun login(newUser: User, accessToken: String)
abstract fun login(newUser: User)

/**
* Call when a user should be logged out.
Expand Down Expand Up @@ -106,10 +112,18 @@ class CurrentUserV2(
override val accessToken: String?
get() = accessTokenPreference.get()

override fun login(newUser: User, accessToken: String) {
override fun login(newUser: User) {
Timber.d("Login user %s", newUser.name())
accessTokenPreference.set(accessToken)
user.onNext(KsOptional.of(newUser))
}

override fun setToken(accessToken: String) {
// - Clean previous token in case there is any
accessTokenPreference.delete()
deviceRegistrar.unregisterDevice()

// - Register new token
accessTokenPreference.set(accessToken)
deviceRegistrar.registerDevice()
}

Expand Down

This file was deleted.

Loading

0 comments on commit 925af00

Please sign in to comment.