-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #460 from ably/enable_authorise
Enable authorise
- Loading branch information
Showing
37 changed files
with
2,091 additions
and
1,058 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
1,785 changes: 925 additions & 860 deletions
1,785
android/src/main/java/io/ably/flutter/plugin/AblyMessageCodec.java
Large diffs are not rendered by default.
Oops, something went wrong.
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
98 changes: 98 additions & 0 deletions
98
android/src/main/java/io/ably/flutter/plugin/AuthMethodHandler.java
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,98 @@ | ||
package io.ably.flutter.plugin; | ||
|
||
import android.os.Handler; | ||
import android.os.Looper; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
|
||
import io.ably.flutter.plugin.generated.PlatformConstants; | ||
import io.ably.lib.rest.Auth; | ||
import io.ably.lib.types.AblyException; | ||
import io.flutter.plugin.common.MethodCall; | ||
import io.flutter.plugin.common.MethodChannel; | ||
|
||
class AuthMethodHandler { | ||
enum Type{Realtime,Rest} | ||
|
||
private final AblyInstanceStore instanceStore; | ||
private final ExecutorService executor = Executors.newSingleThreadExecutor(); | ||
|
||
public AuthMethodHandler(AblyInstanceStore instanceStore) { | ||
this.instanceStore = instanceStore; | ||
|
||
} | ||
|
||
void authorize(@NonNull MethodCall methodCall, @NonNull MethodChannel.Result result, Type type) { | ||
final AblyFlutterMessage<Map<String, Object>> ablyMessage = (AblyFlutterMessage) methodCall.arguments; | ||
final Auth.TokenParams tokenParams = | ||
(Auth.TokenParams) ablyMessage.message.get(PlatformConstants.TxTransportKeys.params); | ||
|
||
final Auth.AuthOptions options = | ||
(Auth.AuthOptions) ablyMessage.message.get(PlatformConstants.TxTransportKeys.options); | ||
|
||
executor.execute(() -> { | ||
try { | ||
final Auth.TokenDetails tokenDetails = getAuth(ablyMessage, type) | ||
.authorize(tokenParams, options); | ||
result.success(tokenDetails); | ||
} catch (AblyException e) { | ||
result.error(String.valueOf(e.errorInfo.code), e.errorInfo.message, e); | ||
} | ||
}); | ||
|
||
} | ||
|
||
private Auth getAuth(AblyFlutterMessage<Map<String, Object>> ablyMessage, Type type) { | ||
if (type == Type.Realtime) { | ||
return instanceStore.getRealtime(ablyMessage.handle).auth; | ||
} | ||
return instanceStore.getRest(ablyMessage.handle).auth; | ||
} | ||
|
||
void requestToken(@NonNull MethodCall methodCall, @NonNull MethodChannel.Result result, Type type) { | ||
final AblyFlutterMessage<Map<String, Object>> ablyMessage = (AblyFlutterMessage) methodCall.arguments; | ||
final Auth.TokenParams tokenParams = | ||
(Auth.TokenParams) ablyMessage.message.get(PlatformConstants.TxTransportKeys.params); | ||
|
||
final Auth.AuthOptions options = | ||
(Auth.AuthOptions) ablyMessage.message.get(PlatformConstants.TxTransportKeys.options); | ||
|
||
executor.execute(() -> { | ||
try { | ||
final Auth.TokenDetails tokenDetails = getAuth(ablyMessage, type) | ||
.requestToken(tokenParams, options); | ||
result.success(tokenDetails); | ||
} catch (AblyException e) { | ||
result.error(String.valueOf(e.errorInfo.code), e.errorInfo.message, e); | ||
} | ||
}); | ||
} | ||
|
||
void createTokenRequest(@NonNull MethodCall methodCall, @NonNull MethodChannel.Result result, Type type) { | ||
final AblyFlutterMessage<Map<String, Object>> ablyMessage = (AblyFlutterMessage) methodCall.arguments; | ||
final Auth.TokenParams tokenParams = | ||
(Auth.TokenParams) ablyMessage.message.get(PlatformConstants.TxTransportKeys.params); | ||
|
||
final Auth.AuthOptions options = | ||
(Auth.AuthOptions) ablyMessage.message.get(PlatformConstants.TxTransportKeys.options); | ||
|
||
executor.execute(() -> { | ||
try { | ||
final Auth.TokenRequest tokenRequest = getAuth(ablyMessage, type) | ||
.createTokenRequest(tokenParams, options); | ||
result.success(tokenRequest); | ||
} catch (AblyException e) { | ||
result.error(String.valueOf(e.errorInfo.code), e.errorInfo.message, e); | ||
} | ||
}); | ||
} | ||
|
||
public void clientId(MethodCall methodCall, MethodChannel.Result result, Type type) { | ||
String clientId = getAuth((AblyFlutterMessage) methodCall.arguments, type).clientId; | ||
result.success(clientId); | ||
} | ||
} |
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
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
Oops, something went wrong.