1 /* 2 * 3 * Copyright 2015 gRPC authors. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 */ 18 19 #import "GRPCCall.h" 20 21 /** 22 * The protocol of an OAuth2 token object from which GRPCCall can acquire a token. 23 */ 24 @protocol GRPCAuthorizationProtocol 25 - (void)getTokenWithHandler:(void (^)(NSString *token))hander; 26 @end 27 28 /** Helpers for setting and reading headers compatible with OAuth2. */ 29 @interface GRPCCall (OAuth2) 30 31 /** 32 * Setting this property is equivalent to setting "Bearer <passed token>" as the value of the 33 * request header with key "authorization" (the authorization header). Setting it to nil removes the 34 * authorization header from the request. 35 * The value obtained by getting the property is the OAuth2 bearer token if the authorization header 36 * of the request has the form "Bearer <token>", or nil otherwise. 37 */ 38 @property(atomic, copy) NSString *oauth2AccessToken; 39 40 /** Returns the value (if any) of the "www-authenticate" response header (the challenge header). */ 41 @property(atomic, readonly) NSString *oauth2ChallengeHeader; 42 43 /** 44 * The authorization token object to be used when starting the call. If the value is set to nil, no 45 * oauth authentication will be used. 46 * 47 * If tokenProvider exists, it takes precedence over the token set by oauth2AccessToken. 48 */ 49 @property(atomic, strong) id<GRPCAuthorizationProtocol> tokenProvider; 50 51 @end 52