|
|
@ -35,7 +35,6 @@ |
|
|
|
|
|
|
|
|
|
|
|
#import <AuthTestService/AuthSample.pbrpc.h> |
|
|
|
#import <AuthTestService/AuthSample.pbrpc.h> |
|
|
|
#import <Google/SignIn.h> |
|
|
|
#import <Google/SignIn.h> |
|
|
|
#include <grpc/status.h> |
|
|
|
|
|
|
|
#import <ProtoRPC/ProtoRPC.h> |
|
|
|
#import <ProtoRPC/ProtoRPC.h> |
|
|
|
|
|
|
|
|
|
|
|
NSString * const kTestScope = @"https://www.googleapis.com/auth/xapi.zoo"; |
|
|
|
NSString * const kTestScope = @"https://www.googleapis.com/auth/xapi.zoo"; |
|
|
@ -49,10 +48,10 @@ static NSString * const kTestHostAddress = @"grpc-test.sandbox.google.com"; |
|
|
|
|
|
|
|
|
|
|
|
@implementation NSError (AuthSample) |
|
|
|
@implementation NSError (AuthSample) |
|
|
|
- (NSString *)UIDescription { |
|
|
|
- (NSString *)UIDescription { |
|
|
|
if (self.code == GRPC_STATUS_UNAUTHENTICATED) { |
|
|
|
if (self.code == GRPCErrorCodeUnauthenticated) { |
|
|
|
// Authentication error. OAuth2 specifies we'll receive a challenge header. |
|
|
|
// Authentication error. OAuth2 specifies we'll receive a challenge header. |
|
|
|
// |userInfo[kGRPCStatusMetadataKey]| is the dictionary of response metadata. |
|
|
|
// |userInfo[kGRPCHeadersKey]| is the dictionary of response headers. |
|
|
|
NSString *challengeHeader = self.userInfo[kGRPCStatusMetadataKey][@"www-authenticate"] ?: @""; |
|
|
|
NSString *challengeHeader = self.userInfo[kGRPCHeadersKey][@"www-authenticate"] ?: @""; |
|
|
|
return [@"Invalid credentials. Server challenge:\n" stringByAppendingString:challengeHeader]; |
|
|
|
return [@"Invalid credentials. Server challenge:\n" stringByAppendingString:challengeHeader]; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
// Any other error. |
|
|
|
// Any other error. |
|
|
@ -89,7 +88,7 @@ static NSString * const kTestHostAddress = @"grpc-test.sandbox.google.com"; |
|
|
|
|
|
|
|
|
|
|
|
// Set the access token to be used. |
|
|
|
// Set the access token to be used. |
|
|
|
NSString *accessToken = GIDSignIn.sharedInstance.currentUser.authentication.accessToken; |
|
|
|
NSString *accessToken = GIDSignIn.sharedInstance.currentUser.authentication.accessToken; |
|
|
|
call.requestMetadata[@"Authorization"] = [@"Bearer " stringByAppendingString:accessToken]; |
|
|
|
call.requestHeaders[@"Authorization"] = [@"Bearer " stringByAppendingString:accessToken]; |
|
|
|
|
|
|
|
|
|
|
|
// Start the RPC. |
|
|
|
// Start the RPC. |
|
|
|
[call start]; |
|
|
|
[call start]; |
|
|
|