Jorge Canizales | 594ae57 | 2015-08-06 22:08:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 3 | * Copyright 2015 gRPC authors. |
Jorge Canizales | 594ae57 | 2015-08-06 22:08:53 -0700 | [diff] [blame] | 4 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 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 |
Jorge Canizales | 594ae57 | 2015-08-06 22:08:53 -0700 | [diff] [blame] | 8 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
Jorge Canizales | 594ae57 | 2015-08-06 22:08:53 -0700 | [diff] [blame] | 10 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 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. |
Jorge Canizales | 594ae57 | 2015-08-06 22:08:53 -0700 | [diff] [blame] | 16 | * |
| 17 | */ |
| 18 | |
| 19 | #import "GRPCCall.h" |
| 20 | |
Muxi Yan | b82f82b | 2017-08-14 12:01:14 -0700 | [diff] [blame] | 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 | |
Jorge Canizales | 88c3284 | 2015-10-26 10:18:59 -0700 | [diff] [blame] | 28 | /** Helpers for setting and reading headers compatible with OAuth2. */ |
Jorge Canizales | 594ae57 | 2015-08-06 22:08:53 -0700 | [diff] [blame] | 29 | @interface GRPCCall (OAuth2) |
| 30 | |
Jorge Canizales | 88c3284 | 2015-10-26 10:18:59 -0700 | [diff] [blame] | 31 | /** |
Muxi Yan | 2c88b46 | 2016-10-28 10:47:25 -0700 | [diff] [blame] | 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. |
Jorge Canizales | 88c3284 | 2015-10-26 10:18:59 -0700 | [diff] [blame] | 37 | */ |
Jorge Canizales | 721b7a3 | 2015-08-07 10:11:16 -0700 | [diff] [blame] | 38 | @property(atomic, copy) NSString *oauth2AccessToken; |
Jorge Canizales | 594ae57 | 2015-08-06 22:08:53 -0700 | [diff] [blame] | 39 | |
Muxi Yan | 2c88b46 | 2016-10-28 10:47:25 -0700 | [diff] [blame] | 40 | /** Returns the value (if any) of the "www-authenticate" response header (the challenge header). */ |
Jorge Canizales | 721b7a3 | 2015-08-07 10:11:16 -0700 | [diff] [blame] | 41 | @property(atomic, readonly) NSString *oauth2ChallengeHeader; |
Jorge Canizales | 594ae57 | 2015-08-06 22:08:53 -0700 | [diff] [blame] | 42 | |
Muxi Yan | b82f82b | 2017-08-14 12:01:14 -0700 | [diff] [blame] | 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 | |
Jorge Canizales | 594ae57 | 2015-08-06 22:08:53 -0700 | [diff] [blame] | 51 | @end |