blob: adb1042aa0ebbbce8a48c729819c973e8e0c587d [file] [log] [blame]
Jorge Canizales594ae572015-08-06 22:08:53 -07001/*
2 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02003 * Copyright 2015 gRPC authors.
Jorge Canizales594ae572015-08-06 22:08:53 -07004 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02005 * 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
Jorge Canizales594ae572015-08-06 22:08:53 -07008 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02009 * http://www.apache.org/licenses/LICENSE-2.0
Jorge Canizales594ae572015-08-06 22:08:53 -070010 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +020011 * 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.
Jorge Canizales594ae572015-08-06 22:08:53 -070016 *
17 */
18
19#import "GRPCCall.h"
20
Muxi Yanb82f82b2017-08-14 12:01:14 -070021/**
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
Jorge Canizales88c32842015-10-26 10:18:59 -070028/** Helpers for setting and reading headers compatible with OAuth2. */
Jorge Canizales594ae572015-08-06 22:08:53 -070029@interface GRPCCall (OAuth2)
30
Jorge Canizales88c32842015-10-26 10:18:59 -070031/**
Muxi Yan2c88b462016-10-28 10:47:25 -070032 * 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.
Jorge Canizales88c32842015-10-26 10:18:59 -070037 */
Jorge Canizales721b7a32015-08-07 10:11:16 -070038@property(atomic, copy) NSString *oauth2AccessToken;
Jorge Canizales594ae572015-08-06 22:08:53 -070039
Muxi Yan2c88b462016-10-28 10:47:25 -070040/** Returns the value (if any) of the "www-authenticate" response header (the challenge header). */
Jorge Canizales721b7a32015-08-07 10:11:16 -070041@property(atomic, readonly) NSString *oauth2ChallengeHeader;
Jorge Canizales594ae572015-08-06 22:08:53 -070042
Muxi Yanb82f82b2017-08-14 12:01:14 -070043/**
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
Jorge Canizales594ae572015-08-06 22:08:53 -070051@end