Rename getTokenWithHandler

pull/16190/head
Muxi Yan 6 years ago
parent f0f6e03212
commit 92db5fc724
  1. 14
      src/objective-c/GRPCClient/GRPCCall.m
  2. 13
      src/objective-c/GRPCClient/GRPCCallOptions.h
  3. 2
      src/objective-c/ProtoRPC/ProtoRPC.m
  4. 2
      src/objective-c/tests/APIv2Tests/APIv2Tests.m

@ -885,7 +885,7 @@ const char *kCFStreamVarName = "grpc_cfstream";
@synchronized(self) {
self.isWaitingForToken = YES;
}
[_callOptions.authTokenProvider getTokenWithHandler:^(NSString *token) {
void (^tokenHandler)(NSString *token) = ^(NSString *token) {
@synchronized(self) {
if (self.isWaitingForToken) {
if (token) {
@ -895,7 +895,17 @@ const char *kCFStreamVarName = "grpc_cfstream";
self.isWaitingForToken = NO;
}
}
}];
};
id<GRPCAuthorizationProtocol> authTokenProvider = _callOptions.authTokenProvider;
if ([authTokenProvider respondsToSelector:@selector(provideTokenToHandler:)]) {
[_callOptions.authTokenProvider provideTokenToHandler:tokenHandler];
} else {
NSAssert([authTokenProvider respondsToSelector:@selector(getTokenWithHandler:)],
@"authTokenProvider has no usable method");
if ([authTokenProvider respondsToSelector:@selector(getTokenWithHandler:)]) {
[_callOptions.authTokenProvider getTokenWithHandler:tokenHandler];
}
}
} else {
[self startCallWithWriteable:writeable];
}

@ -58,13 +58,24 @@ typedef NS_ENUM(NSUInteger, GRPCTransportType) {
/**
* Implement this protocol to provide a token to gRPC when a call is initiated.
*/
@protocol GRPCAuthorizationProtocol
@protocol GRPCAuthorizationProtocol<NSObject>
@optional
/**
* This method is called when gRPC is about to start the call. When OAuth token is acquired,
* \a handler is expected to be called with \a token being the new token to be used for this call.
*/
- (void)provideTokenToHandler:(void (^_Nullable)(NSString *_Nullable token))handler;
/**
* This method is deprecated. Please use \a provideTokenToHandler.
*
* This method is called when gRPC is about to start the call. When OAuth token is acquired,
* \a handler is expected to be called with \a token being the new token to be used for this call.
*/
- (void)getTokenWithHandler:(void (^_Nullable)(NSString *_Nullable token))handler;
@end
@interface GRPCCallOptions : NSObject<NSCopying, NSMutableCopying>

@ -168,7 +168,7 @@ static NSError *ErrorForBadProto(id proto, Class expectedClass, NSError *parsing
}
- (void)writeMessage:(GPBMessage *)message {
NSAssert([message isKindOfClass:[GPBMessage class]]);
NSAssert([message isKindOfClass:[GPBMessage class]], @"Parameter message must be a GPBMessage");
if (![message isKindOfClass:[GPBMessage class]]) {
NSLog(@"Failed to send a message that is non-proto.");
return;

@ -241,7 +241,7 @@ static const NSTimeInterval kTestTimeout = 16;
[self waitForExpectationsWithTimeout:kTestTimeout handler:nil];
}
- (void)getTokenWithHandler:(void (^)(NSString *token))handler {
- (void)provideTokenToHandler:(void (^)(NSString *token))handler {
dispatch_queue_t queue = dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL);
dispatch_sync(queue, ^{
handler(@"test-access-token");

Loading…
Cancel
Save