mirror of https://github.com/grpc/grpc.git
commit
fb94111259
2136 changed files with 168663 additions and 30053 deletions
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,192 @@ |
||||
# gRPC over HTTP2 |
||||
|
||||
## Introduction |
||||
This document serves as a detailed description for an implementation of gRPC carried over HTTP2 draft 17 framing. It assumes familiarity with the HTTP2 specification. |
||||
|
||||
## Protocol |
||||
Production rules are using <a href="http://tools.ietf.org/html/rfc5234">ABNF syntax</a>. |
||||
|
||||
### Outline |
||||
|
||||
The following is the general sequence of message atoms in a GRPC request & response message stream |
||||
|
||||
* Request → Request-Headers *Delimited-Message EOS |
||||
* Response → (Response-Headers *Delimited-Message Trailers) / Trailers-Only |
||||
|
||||
|
||||
### Requests |
||||
|
||||
* Request → Request-Headers *Delimited-Message EOS |
||||
|
||||
Request-Headers are delivered as HTTP2 headers in HEADERS + CONTINUATION frames. |
||||
|
||||
* **Request-Headers** → Call-Definition *Custom-Metadata |
||||
* **Call-Definition** → Method Scheme Path TE [Authority] [Timeout] [Content-Type] [Message-Type] [Message-Encoding] [Message-Accept-Encoding] [User-Agent] |
||||
* **Method** → “:method POST” |
||||
* **Scheme** → “:scheme ” (“http” / “https”) |
||||
* **Path** → “:path” {_path identifying method within exposed API_} |
||||
* **Authority** → “:authority” {_virtual host name of authority_} |
||||
* **TE** → “te” “trailers” # Used to detect incompatible proxies |
||||
* **Timeout** → “grpc-timeout” TimeoutValue TimeoutUnit |
||||
* **TimeoutValue** → {_positive integer as ASCII string of at most 8 digits_} |
||||
* **TimeoutUnit** → Hour / Minute / Second / Millisecond / Microsecond / Nanosecond |
||||
* **Hour** → “H” |
||||
* **Minute** → “M” |
||||
* **Second** → “S” |
||||
* **Millisecond** → “m” |
||||
* **Microsecond** → “u” |
||||
* **Nanosecond** → “n” |
||||
* **Content-Type** → “content-type” “application/grpc” [(“+proto” / “+json” / {_custom_})] |
||||
* **Content-Coding** → “gzip” / “deflate” / “snappy” / {_custom_} |
||||
* **Message-Encoding** → “grpc-encoding” Content-Coding |
||||
* **Message-Accept-Encoding** → “grpc-accept-encoding” Content-Coding *("," Content-Coding) |
||||
* **User-Agent** → “user-agent” {_structured user-agent string_} |
||||
* **Message-Type** → “grpc-message-type” {_type name for message schema_} |
||||
* **Custom-Metadata** → Binary-Header / ASCII-Header |
||||
* **Binary-Header** → {lowercase ASCII header name ending in “-bin” } {_base64 encoded value_} |
||||
* **ASCII-Header** → {lowercase ASCII header name} {_value_} |
||||
|
||||
|
||||
HTTP2 requires that reserved headers, ones starting with “:” appear before all other headers. Additionally implementations should send **Timeout** immediately after the reserved headers and they should send the **Call-Definition** headers before sending **Custom-Metadata**. |
||||
|
||||
If **Timeout** is omitted a server should assume an infinite timeout. Client implementations are free to send a default minimum timeout based on their deployment requirements. |
||||
|
||||
**Custom-Metadata** is an arbitrary set of key-value pairs defined by the application layer. Aside from transport limits on the total length of HTTP2 HEADERS the only other constraint is that header names starting with “grpc-” are reserved for future use. |
||||
|
||||
Note that HTTP2 does not allow arbitrary octet sequences for header values so binary header values must be encoded using Base64 as per https://tools.ietf.org/html/rfc4648#section-4. Implementations MUST accept padded and un-padded values and should emit un-padded values. Applications define binary headers by having their names end with “-bin”. Runtime libraries use this suffix to detect binary headers and properly apply base64 encoding & decoding as headers are sent and received. |
||||
|
||||
The repeated sequence of **Delimited-Message** items is delivered in DATA frames |
||||
|
||||
* **Delimited-Message** → Compressed-Flag Message-Length Message |
||||
* **Compressed-Flag** → 0 / 1 # encoded as 1 byte unsigned integer |
||||
* **Message-Length** → {_length of Message_} # encoded as 4 byte unsigned integer |
||||
* **Message** → *{binary octet} |
||||
|
||||
A **Compressed-Flag** value of 1 indicates that the binary octet sequence of **Message** is compressed using the mechanism declared by the **Message-Encoding** header. A value of 0 indicates that no encoding of **Message** bytes has occurred. Compression contexts are NOT maintained over message boundaries, implementations must create a new context for each message in the stream. If the **Message-Encoding** header is omitted then the **Compressed-Flag** must be 0. |
||||
|
||||
For requests, **EOS** (end-of-stream) is indicated by the presence of the END_STREAM flag on the last received DATA frame. In scenarios where the **Request** stream needs to be closed but no data remains to be sent implementations MUST send an empty DATA frame with this flag set. |
||||
|
||||
###Responses |
||||
|
||||
* **Response** → (Response-Headers *Delimited-Message Trailers) / Trailers-Only |
||||
* **Response-Headers** → HTTP-Status [Message-Encoding] [Message-Accept-Encoding] Content-Type *Custom-Metadata |
||||
* **Trailers-Only** → HTTP-Status Content-Type Trailers |
||||
* **Trailers** → Status [Status-Message] *Custom-Metadata |
||||
* **HTTP-Status** → “:status 200” |
||||
* **Status** → “grpc-status” <status-code-as-ASCII-string> |
||||
* **Status-Message** → “grpc-message” <descriptive text for status as ASCII string> |
||||
|
||||
**Response-Headers** & **Trailers-Only** are each delivered in a single HTTP2 HEADERS frame block. Most responses are expected to have both headers and trailers but **Trailers-Only** is permitted for calls that produce an immediate error. Status must be sent in **Trailers** even if the status code is OK. |
||||
|
||||
For responses end-of-stream is indicated by the presence of the END_STREAM flag on the last received HEADERS frame that carries **Trailers**. |
||||
|
||||
Implementations should expect broken deployments to send non-200 HTTP status codes in responses as well as a variety of non-GRPC content-types and to omit **Status** & **Status-Message**. Implementations must synthesize a **Status** & **Status-Message** to propagate to the application layer when this occurs. |
||||
|
||||
####Example |
||||
|
||||
Sample unary-call showing HTTP2 framing sequence |
||||
|
||||
**Request** |
||||
|
||||
``` |
||||
HEADERS (flags = END_HEADERS) |
||||
:method = POST |
||||
:scheme = http |
||||
:path = /google.pubsub.v2.PublisherService/CreateTopic |
||||
:authority = pubsub.googleapis.com |
||||
grpc-timeout = 1S |
||||
content-type = application/grpc+proto |
||||
grpc-encoding = gzip |
||||
authorization = Bearer y235.wef315yfh138vh31hv93hv8h3v |
||||
|
||||
DATA (flags = END_STREAM) |
||||
<Delimited Message> |
||||
``` |
||||
**Response** |
||||
``` |
||||
HEADERS (flags = END_HEADERS) |
||||
:status = 200 |
||||
grpc-encoding = gzip |
||||
|
||||
DATA |
||||
<Delimited Message> |
||||
|
||||
HEADERS (flags = END_STREAM, END_HEADERS) |
||||
grpc-status = 0 # OK |
||||
trace-proto-bin = jher831yy13JHy3hc |
||||
``` |
||||
####User Agents |
||||
|
||||
While the protocol does not require a user-agent to function it is recommended that clients provide a structured user-agent string that provides a basic description of the calling library, version & platform to facilitate issue diagnosis in heterogeneous environments. The following structure is recommended to library developers |
||||
``` |
||||
User-Agent → “grpc-” Language ?(“-” Variant) “/” Version ?( “ (“ *(AdditionalProperty “;”) “)” ) |
||||
``` |
||||
E.g. |
||||
|
||||
``` |
||||
grpc-java/1.2.3 |
||||
grpc-ruby/1.2.3 |
||||
grpc-ruby-jruby/1.3.4 |
||||
grpc-java-android/0.9.1 (gingerbread/1.2.4; nexus5; tmobile) |
||||
``` |
||||
####HTTP2 Transport Mapping |
||||
|
||||
#####Stream Identification |
||||
All GRPC calls need to specify an internal ID. We will use HTTP2 stream-ids as call identifiers in this scheme. NOTE: These id’s are contextual to an open HTTP2 session and will not be unique within a given process that is handling more than one HTTP2 session nor can they be used as GUIDs. |
||||
|
||||
#####Data Frames |
||||
DATA frame boundaries have no relation to **Delimited-Message** boundaries and implementations should make no assumptions about their alignment. |
||||
|
||||
#####Errors |
||||
|
||||
When an application or runtime error occurs during an RPC a **Status** and **Status-Message** are delivered in **Trailers**. |
||||
|
||||
In some cases it is possible that the framing of the message stream has become corrupt and the RPC runtime will choose to use an **RST_STREAM** frame to indicate this state to its peer. RPC runtime implementations should interpret RST_STREAM as immediate full-closure of the stream and should propagate an error up to the calling application layer. |
||||
|
||||
The following mapping from RST_STREAM error codes to GRPC error codes is applied. |
||||
|
||||
HTTP2 Code|GRPC Code |
||||
----------|----------- |
||||
NO_ERROR(0)|INTERNAL - An explicit GRPC status of OK should have been sent but this might be used to aggressively lameduck in some scenarios. |
||||
PROTOCOL_ERROR(1)|INTERNAL |
||||
INTERNAL_ERROR(2)|INTERNAL |
||||
FLOW_CONTROL_ERROR(3)|INTERNAL |
||||
SETTINGS_TIMEOUT(4)|INTERNAL |
||||
STREAM_CLOSED|No mapping as there is no open stream to propagate to. Implementations should log. |
||||
FRAME_SIZE_ERROR|INTERNAL |
||||
REFUSED_STREAM|UNAVAILABLE - Indicates that no processing occurred and the request can be retried, possibly elsewhere. |
||||
CANCEL(8)|Mapped to call cancellation when sent by a client.Mapped to CANCELLED when sent by a server. Note that servers should only use this mechanism when they need to cancel a call but the payload byte sequence is incomplete. |
||||
COMPRESSION_ERROR|INTERNAL |
||||
CONNECT_ERROR|INTERNAL |
||||
ENHANCE_YOUR_CALM|RESOURCE_EXHAUSTED ...with additional error detail provided by runtime to indicate that the exhausted resource is bandwidth. |
||||
INADEQUATE_SECURITY| PERMISSION_DENIED … with additional detail indicating that permission was denied as protocol is not secure enough for call. |
||||
|
||||
|
||||
#####Security |
||||
|
||||
The HTTP2 specification mandates the use of TLS 1.2 or higher when TLS is used with HTTP2. It also places some additional constraints on the allowed ciphers in deployments to avoid known-problems as well as requiring SNI support. It is also expected that HTTP2 will be used in conjunction with proprietary transport security mechanisms about which the specification can make no meaningful recommendations. |
||||
|
||||
#####Connection Management |
||||
######GOAWAY Frame |
||||
Sent by servers to clients to indicate that they will no longer accept any new streams on the associated connections. This frame includes the id of the last successfully accepted stream by the server. Clients should consider any stream initiated after the last successfully accepted stream as UNAVAILABLE and retry the call elsewhere. Clients are free to continue working with the already accepted streams until they complete or the connection is terminated. |
||||
|
||||
Servers should send GOAWAY before terminating a connection to reliably inform clients which work has been accepted by the server and is being executed. |
||||
|
||||
######PING Frame |
||||
Both clients and servers can send a PING frame that the peer must respond to by precisely echoing what they received. This is used to assert that the connection is still live as well as providing a means to estimate end-to-end latency. If a server initiated PING does not receive a response within the deadline expected by the runtime all outstanding calls on the server will be closed with a CANCELLED status. An expired client initiated PING will cause all calls to be closed with an UNAVAILABLE status. Note that the frequency of PINGs is highly dependent on the network environment, implementations are free to adjust PING frequency based on network and application requirements. |
||||
|
||||
######Connection failure |
||||
If a detectable connection failure occurs on the client all calls will be closed with an UNAVAILABLE status. For servers open calls will be closed with a CANCELLED status. |
||||
|
||||
|
||||
### Appendix A - GRPC for Protobuf |
||||
|
||||
The service interfaces declared by protobuf are easily mapped onto GRPC by code generation extensions to protoc. The following defines the mapping to be used |
||||
|
||||
|
||||
* **Path** → / Service-Name / {_method name_} |
||||
* **Service-Name** → ?( {_proto package name_} "." ) {_service name_} |
||||
* **Message-Type** → {_fully qualified proto message name_} |
||||
* **Content-Type** → "application/grpc+proto" |
||||
|
||||
|
@ -0,0 +1,289 @@ |
||||
#gRPC Authentication support |
||||
|
||||
gRPC is designed to plug-in a number of authentication mechanisms. This document |
||||
provides a quick overview of the various auth mechanisms supported, discusses |
||||
the API with some examples, and concludes with a discussion of extensibility. |
||||
More documentation and examples are coming soon! |
||||
|
||||
## Supported auth mechanisms |
||||
|
||||
###SSL/TLS |
||||
gRPC has SSL/TLS integration and promotes the use of SSL/TLS to authenticate the |
||||
server, and encrypt all the data exchanged between the client and the server. |
||||
Optional mechanisms are available for clients to provide certificates to |
||||
accomplish mutual authentication. |
||||
|
||||
###OAuth 2.0 |
||||
gRPC provides a generic mechanism (described below) to attach metadata to |
||||
requests and responses. This mechanism can be used to attach OAuth 2.0 Access |
||||
Tokens to RPCs being made at a client. Additional support for acquiring Access |
||||
Tokens while accessing Google APIs through gRPC is provided for certain auth |
||||
flows, demonstrated through code examples below. |
||||
|
||||
## API |
||||
To reduce complexity and minimize API clutter, gRPC works with a unified concept |
||||
of a Credentials object. Users construct gRPC credentials using corresponding |
||||
bootstrap credentials (e.g., SSL client certs or Service Account Keys), and use |
||||
the credentials while creating a gRPC channel to any server. Depending on the |
||||
type of credential supplied, the channel uses the credentials during the initial |
||||
SSL/TLS handshake with the server, or uses the credential to generate and |
||||
attach Access Tokens to each request being made on the channel. |
||||
|
||||
###SSL/TLS for server authentication and encryption |
||||
This is the simplest authentication scenario, where a client just wants to |
||||
authenticate the server and encrypt all data. |
||||
|
||||
```cpp |
||||
SslCredentialsOptions ssl_opts; // Options to override SSL params, empty by default |
||||
// Create the credentials object by providing service account key in constructor |
||||
std::unique_ptr<Credentials> creds = CredentialsFactory::SslCredentials(ssl_opts); |
||||
// Create a channel using the credentials created in the previous step |
||||
std::shared_ptr<ChannelInterface> channel = CreateChannel(server_name, creds, channel_args); |
||||
// Create a stub on the channel |
||||
std::unique_ptr<Greeter::Stub> stub(Greeter::NewStub(channel)); |
||||
// Make actual RPC calls on the stub. |
||||
grpc::Status s = stub->sayHello(&context, *request, response); |
||||
``` |
||||
|
||||
For advanced use cases such as modifying the root CA or using client certs, |
||||
the corresponding options can be set in the SslCredentialsOptions parameter |
||||
passed to the factory method. |
||||
|
||||
|
||||
###Authenticating with Google |
||||
|
||||
gRPC applications can use a simple API to create a credential that works in various deployment scenarios. |
||||
|
||||
```cpp |
||||
std::unique_ptr<Credentials> creds = CredentialsFactory::GoogleDefaultCredentials(); |
||||
// Create a channel, stub and make RPC calls (same as in the previous example) |
||||
std::shared_ptr<ChannelInterface> channel = CreateChannel(server_name, creds, channel_args); |
||||
std::unique_ptr<Greeter::Stub> stub(Greeter::NewStub(channel)); |
||||
grpc::Status s = stub->sayHello(&context, *request, response); |
||||
``` |
||||
|
||||
This credential works for applications using Service Accounts as well as for |
||||
applications running in [Google Compute Engine (GCE)](https://cloud.google.com/compute/). In the former case, the |
||||
service account’s private keys are loaded from the file named in the environment |
||||
variable `GOOGLE_APPLICATION_CREDENTIALS`. The |
||||
keys are used to generate bearer tokens that are attached to each outgoing RPC |
||||
on the corresponding channel. |
||||
|
||||
For applications running in GCE, a default service account and corresponding |
||||
OAuth scopes can be configured during VM setup. At run-time, this credential |
||||
handles communication with the authentication systems to obtain OAuth2 access |
||||
tokens and attaches them to each outgoing RPC on the corresponding channel. |
||||
Extending gRPC to support other authentication mechanisms |
||||
The gRPC protocol is designed with a general mechanism for sending metadata |
||||
associated with RPC. Clients can send metadata at the beginning of an RPC and |
||||
servers can send back metadata at the beginning and end of the RPC. This |
||||
provides a natural mechanism to support OAuth2 and other authentication |
||||
mechanisms that need attach bearer tokens to individual request. |
||||
|
||||
In the simplest case, there is a single line of code required on the client |
||||
to add a specific token as metadata to an RPC and a corresponding access on |
||||
the server to retrieve this piece of metadata. The generation of the token |
||||
on the client side and its verification at the server can be done separately. |
||||
|
||||
A deeper integration can be achieved by plugging in a gRPC credentials implementation for any custom authentication mechanism that needs to attach per-request tokens. gRPC internals also allow switching out SSL/TLS with other encryption mechanisms. |
||||
|
||||
## Examples |
||||
|
||||
These authentication mechanisms will be available in all gRPC's supported languages. |
||||
The following sections demonstrate how authentication and authorization features described above appear in each language: more languages are coming soon. |
||||
|
||||
###SSL/TLS for server authentication and encryption (Ruby) |
||||
```ruby |
||||
# Base case - No encryption |
||||
stub = Helloworld::Greeter::Stub.new('localhost:50051') |
||||
... |
||||
|
||||
# With server authentication SSL/TLS |
||||
creds = GRPC::Core::Credentials.new(load_certs) # load_certs typically loads a CA roots file |
||||
stub = Helloworld::Greeter::Stub.new('localhost:50051', creds: creds) |
||||
``` |
||||
|
||||
###SSL/TLS for server authentication and encryption (C#) |
||||
```csharp |
||||
// Base case - No encryption |
||||
var channel = new Channel("localhost:50051"); |
||||
var client = new Greeter.GreeterClient(channel); |
||||
... |
||||
|
||||
// With server authentication SSL/TLS |
||||
var credentials = new SslCredentials(File.ReadAllText("ca.pem")); // Load a CA file |
||||
var channel = new Channel("localhost:50051", credentials); |
||||
var client = new Greeter.GreeterClient(channel); |
||||
``` |
||||
|
||||
###SSL/TLS for server authentication and encryption (Objective-C) |
||||
|
||||
The default for Objective-C is to use SSL/TLS, as that's the most common use case when accessing |
||||
remote APIs. |
||||
|
||||
```objective-c |
||||
// Base case - With server authentication SSL/TLS |
||||
HLWGreeter *client = [[HLWGreeter alloc] initWithHost:@"localhost:50051"]; |
||||
// Same as using @"https://localhost:50051". |
||||
... |
||||
|
||||
// No encryption |
||||
HLWGreeter *client = [[HLWGreeter alloc] initWithHost:@"http://localhost:50051"]; |
||||
// Specifying the HTTP scheme explicitly forces no encryption. |
||||
``` |
||||
|
||||
###SSL/TLS for server authentication and encryption (Python) |
||||
```python |
||||
# Base case - No encryption |
||||
stub = early_adopter_create_GreeterService_stub('localhost', 50051) |
||||
... |
||||
|
||||
# With server authentication SSL/TLS |
||||
stub = early_adopter_create_GreeterService_stub( |
||||
'localhost', 50051, secure=True, root_certificates=open('ca.pem').read()) |
||||
... |
||||
``` |
||||
n.b.: the beta API will look different |
||||
|
||||
###Authenticating with Google (Ruby) |
||||
```ruby |
||||
# Base case - No encryption/authorization |
||||
stub = Helloworld::Greeter::Stub.new('localhost:50051') |
||||
... |
||||
|
||||
# Authenticating with Google |
||||
require 'googleauth' # from http://www.rubydoc.info/gems/googleauth/0.1.0 |
||||
... |
||||
creds = GRPC::Core::Credentials.new(load_certs) # load_certs typically loads a CA roots file |
||||
scope = 'https://www.googleapis.com/auth/grpc-testing' |
||||
authorization = Google::Auth.get_application_default(scope) |
||||
stub = Helloworld::Greeter::Stub.new('localhost:50051', |
||||
creds: creds, |
||||
update_metadata: authorization.updater_proc) |
||||
``` |
||||
|
||||
###Authenticating with Google (Node.js) |
||||
|
||||
```node |
||||
// Base case - No encryption/authorization |
||||
var stub = new helloworld.Greeter('localhost:50051'); |
||||
... |
||||
// Authenticating with Google |
||||
var GoogleAuth = require('google-auth-library'); // from https://www.npmjs.com/package/google-auth-library |
||||
... |
||||
var creds = grpc.Credentials.createSsl(load_certs); // load_certs typically loads a CA roots file |
||||
var scope = 'https://www.googleapis.com/auth/grpc-testing'; |
||||
(new GoogleAuth()).getApplicationDefault(function(err, auth) { |
||||
if (auth.createScopeRequired()) { |
||||
auth = auth.createScoped(scope); |
||||
} |
||||
var stub = new helloworld.Greeter('localhost:50051', |
||||
{credentials: creds}, |
||||
grpc.getGoogleAuthDelegate(auth)); |
||||
}); |
||||
``` |
||||
|
||||
###Authenticating with Google (C#) |
||||
```csharp |
||||
// Base case - No encryption/authorization |
||||
var channel = new Channel("localhost:50051"); |
||||
var client = new Greeter.GreeterClient(channel); |
||||
... |
||||
|
||||
// Authenticating with Google |
||||
using Grpc.Auth; // from Grpc.Auth NuGet package |
||||
... |
||||
var credentials = new SslCredentials(File.ReadAllText("ca.pem")); // Load a CA file |
||||
var channel = new Channel("localhost:50051", credentials); |
||||
|
||||
string scope = "https://www.googleapis.com/auth/grpc-testing"; |
||||
var authorization = GoogleCredential.GetApplicationDefault(); |
||||
if (authorization.IsCreateScopedRequired) |
||||
{ |
||||
authorization = credential.CreateScoped(new[] { scope }); |
||||
} |
||||
var client = new Greeter.GreeterClient(channel, |
||||
new StubConfiguration(OAuth2InterceptorFactory.Create(credential))); |
||||
``` |
||||
|
||||
###Authenticating with Google (PHP) |
||||
```php |
||||
// Base case - No encryption/authorization |
||||
$client = new helloworld\GreeterClient( |
||||
new Grpc\BaseStub('localhost:50051', [])); |
||||
... |
||||
|
||||
// Authenticating with Google |
||||
// the environment variable "GOOGLE_APPLICATION_CREDENTIALS" needs to be set |
||||
$scope = "https://www.googleapis.com/auth/grpc-testing"; |
||||
$auth = Google\Auth\ApplicationDefaultCredentials::getCredentials($scope); |
||||
$opts = [ |
||||
'credentials' => Grpc\Credentials::createSsl(file_get_contents('ca.pem')); |
||||
'update_metadata' => $auth->getUpdateMetadataFunc(), |
||||
]; |
||||
|
||||
$client = new helloworld\GreeterClient( |
||||
new Grpc\BaseStub('localhost:50051', $opts)); |
||||
|
||||
``` |
||||
|
||||
###Authenticating with Google (Objective-C) |
||||
|
||||
This example uses the [Google iOS Sign-In library](https://developers.google.com/identity/sign-in/ios/), |
||||
but it's easily extrapolated to any other OAuth2 library. |
||||
|
||||
```objective-c |
||||
// Base case - No authentication |
||||
[client sayHelloWithRequest:request handler:^(HLWHelloReply *response, NSError *error) { |
||||
... |
||||
}]; |
||||
|
||||
... |
||||
|
||||
// Authenticating with Google |
||||
|
||||
// When signing the user in, ask her for the relevant scopes. |
||||
GIDSignIn.sharedInstance.scopes = @[@"https://www.googleapis.com/auth/grpc-testing"]; |
||||
|
||||
... |
||||
|
||||
#import <ProtoRPC/ProtoRPC.h> |
||||
|
||||
// Create a not-yet-started RPC. We want to set the request headers on this object before starting |
||||
// it. |
||||
ProtoRPC *call = |
||||
[client RPCToSayHelloWithRequest:request handler:^(HLWHelloReply *response, NSError *error) { |
||||
... |
||||
}]; |
||||
|
||||
// Set the access token to be used. |
||||
NSString *accessToken = GIDSignIn.sharedInstance.currentUser.authentication.accessToken; |
||||
call.requestMetadata[@"Authorization"] = [@"Bearer " stringByAppendingString:accessToken]}]; |
||||
|
||||
// Start the RPC. |
||||
[call start]; |
||||
``` |
||||
|
||||
You can see a working example app, with a more detailed explanation, [here](examples/objective-c/auth_sample). |
||||
|
||||
### Authenticating with Google (Python) |
||||
```python |
||||
# Base case - No encryption |
||||
stub = early_adopter_create_GreeterService_stub('localhost', 50051) |
||||
... |
||||
|
||||
# With server authentication SSL/TLS |
||||
import oauth2client.client |
||||
credentials = oauth2client.GoogleCredentials.get_application_default() |
||||
scope = 'https://www.googleapis.com/auth/grpc-testing' |
||||
scoped_credentials = credentials.create_scoped([scope]) |
||||
access_token = scoped_credentials.get_access_token().access_token |
||||
metadata_transformer = ( |
||||
lambda x: [('Authorization', 'Bearer {}'.format(access_token))]) |
||||
|
||||
stub = early_adopter_create_GreeterService_stub( |
||||
'localhost', 50051, secure=True, root_certificates=open('ca.pem').read(), |
||||
metadata_transformer=metadata_transformer) |
||||
... |
||||
``` |
||||
n.b.: the beta API will look different |
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1 +1 @@ |
||||
{"http2initialsequencenumber":[196609,786437,22151169],"http2":[196610,786433,851969,22151170],"headers":[327681,1245185,2097153,3604482,5963783,6029320,9764868,12320771,13697025,13762561,13828097,13893633,14024706,15990785,16121857,16252929,16449537,17039366,21561345,21626881,21692417,21757953,21889027,22872065,23658499,24051714],"hash":[1769473,1835009,1900545,1966081,2031617,2097153,2228225,2293761,2359297,2424833,2490369,2555905,2621441,2949121,3014657,3211265,3276801,3342337,3407873,3473409,3538945,3604481,3670017,3735553,3801089,3866625,3932161,3997697,4063233,4128769,4194305,4456449,21561345,21626881,21692417,21757953,21823489,21889025,22020097,22085633,22347777,22544385,22609921,22675457,22806529,23330817,23396353,23592961,23658497,23724033,23855105,23920641,23986177,24051713,24117249,24182785,24248321,24313857,24444929,24510465,24576001,24641537,24707073,25231361],"handlers":[3997697,10682369,12320771,22609921,23265281,24248321,24510465],"headerinterceptor":[4521989,4587525,12320769,14221313,17760268,22347777,22872069],"header":[4521985,4587521,14221313,17760257,22347777],"host":[5701639,5767174,6750209,6815751,9895942,10551302,12648450,13959170,14221315,15400962,15532033,16580614,17825799,19922950,20578311,21823490,22020098,22347779,24051714,24182785],"holding":[9043969,13041665,23724033],"handler":[9961478,10027014,10092550,10158086,12320773,22413313,22740993,23658497,24379393,24838145],"helper":[12320769,21954561],"hosts":[14221313,17825793,22347777],"helplink":[15269889,23920641],"help":[15269889,23920641],"hresult":[15269890,23920642],"hierarchy":[21495809,21561345,21626881,21692417,21757953,21954561,22020097,22085633,22151169,22347777,22544385,22609921,22675457,22806529,23330817,23396353,23527425,23658497,23855105,23920641,23986177,24051713,24117249,24182785,24248321,24313857,24444929,24510465,24576001,24641537,24903681,24969217,25034753,25100289,25231361],"high":[22478850],"hint":[25165825]} |
||||
{"http2initialsequencenumber":[196609,786437,22151169],"http2":[196610,786433,851969,22151170],"headers":[327681,1245185,2097153,3604482,5963783,6029320,9764868,12320771,13697025,13762561,13828097,13893633,14024706,15990785,16121857,16252929,16449537,17039366,21561345,21626881,21692417,21757953,21889027,22872065,23658499,24051714],"hash":[1769473,1835009,1900545,1966081,2031617,2097153,2228225,2293761,2359297,2424833,2490369,2555905,2621441,2949121,3014657,3211265,3276801,3342337,3407873,3473409,3538945,3604481,3670017,3735553,3801089,3866625,3932161,3997697,4063233,4128769,4194305,4456449,21561345,21626881,21692417,21757953,21823489,21889025,22020097,22085633,22347777,22544385,22609921,22675457,22806529,23330817,23396353,23592961,23658497,23724033,23855105,23920641,23986177,24051713,24117249,24182785,24248321,24313857,24444929,24510465,24576001,24641537,24707073,25231361],"handlers":[3997697,10682369,12320771,22609921,23265281,24248321,24510465],"headerinterceptor":[4521989,4587525,12320769,14221313,17760268,22347777,22872069],"header":[4521985,4587521,14221313,17760257,22347777],"host":[5701639,5767174,6750209,6815751,9895942,10551302,12648450,13959170,14221315,15400962,15532033,16580614,17825799,19922950,20578311,21823490,22020098,22347779,24051714,24182785],"holding":[9043969,13041665,23724033],"handler":[9961478,10027014,10092550,10158086,12320773,22413313,22740993,23658497,24379393,24838145],"helper":[12320769,21954561],"hosts":[14221313,17825793,22347777],"helplink":[15269889,23920641],"help":[15269889,23920641],"hresult":[15269890,23920642],"hierarchy":[21495809,21561345,21626881,21692417,21757953,21954561,22020097,22085633,22151169,22347777,22544385,22609921,22675457,22806529,23330817,23396353,23527425,23592961,23658497,23855105,23920641,23986177,24051713,24117249,24182785,24248321,24313857,24444929,24510465,24576001,24641537,24903681,24969217,25034753,25100289,25231361],"high":[22478850],"hint":[25165825]} |
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1 +1 @@ |
||||
{"occurs":[131073,2228225,6684673,22020097,23920641],"object":[131073,1769480,1835015,1900551,1966088,2031618,2097154,2228235,2293767,2359307,2424843,2490379,2555915,2621451,2949127,3014671,3080196,3211266,3276807,3342338,3407883,3473416,3538955,3604491,3670027,3735563,3801100,3866635,3932171,3997707,4063239,4128779,4194306,4456459,4718593,5373953,6094849,6160385,6225921,6291457,7405577,7471115,7536650,7667721,7733259,7798794,7929863,7995401,8060936,8192007,8257545,8323080,10223617,10354690,11468801,11534337,11599873,11665409,12320769,12713986,12779522,12845058,12910594,15269889,21495809,21561353,21626888,21692424,21757961,21823490,21889026,21954562,22020108,22085640,22151169,22347788,22544396,22609932,22675468,22806540,23330824,23396368,23461892,23527425,23592962,23658504,23724034,23855116,23920651,23986188,24051724,24117260,24182796,24248333,24313868,24444940,24510476,24576008,24641548,24707074,24903681,24969217,25034753,25100289,25231372],"override":[196609,1114113,4653057,4915201,5111809,5308417,7405569,7471105,7536641,7602177,7667713,7733249,7798785,8519681,8716289,8781825,8847361,8912899,9109505,9175041,9240577,9306113,9371649,10616833,10747905,11337731,18874369,19202049,19267585,19333121,19398657,19595265,19660801,22151169],"options":[262145,589825,1179649,1638401,2031617,5570567,5636102,5701638,5767174,6029313,6750216,6815752,6881286,7012353,9699336,10944520,12320773,13959170,14024705,14548994,14614530,14680065,14811138,15400961,16711686,17170433,18153474,18219009,20316161,21823491,21889026,22151169,22544387,23003138,23068674,23134210,23265282,24051713,25231362],"oauth2":[1703937,4521986,12255233,21430273,21495809],"obtain":[1703937,4587522,21495809],"operations":[1769473,1835009,1900545,1966081,2228225,2359297,2424833,2490369,2555905,2621441,3014657,3407873,3473409,3538945,3604481,3670017,3735553,3801089,3866625,3932161,3997697,4128769,4456449,4653057,4915201,5111809,5308417,12320770,21561345,21626881,21692417,21757953,22020097,22347777,22544385,22609921,22675457,22806529,23396353,23855105,23920641,23986177,24051713,24117249,24182785,24248321,24313857,24444929,24510465,24641537,24772609,25165825,25231362],"one":[2752513,2818049,2883585,3473409,7208961,12320769,23003137,23068673,23265281,23920641,23986177,24772609],"overrides":[3342337,4194305,8912897,11337729,23724033,24707073],"overridden":[3473410,23920642],"overload":[5636097,5701633,5767169,6422529,6488065,6750209,6815745,7471105,7536641,7733249,7798785,7995393,8060929,8257537,8323073,8519681,8585217,8650753,8978433,9043969,9568257,9633793,9961473,10027009,10092545,10158081,10485761,10551297,11010049,11075585,11141121,11206657,11272193,11599873,11665409,11796481,11862017,11927553,11993089,12058625,12124161,12517377,12582913,12648449,12713985,12779521,12845057,12910593,12976129,13041665,13107201,13172737,13238273,13303809,13369345,13434881,13500417,13565953,13631489],"optional":[6029322,6553602,6684674,6750210,6815746,7012356,9699330,10944514,11599874,12189698,12320769,24707073],"obtained":[6029313],"option":[6422529,6488065,12320769,12582914,22085635,22216706],"omit":[11468801,11534337,11599873,11665409],"objects":[12320771,22020097,23134209,24248321],"operation":[12320769,22020097,24772618],"optiontype":[12320769,17432582,22216709],"original":[14090241,17629185,22020097],"operatio":[24772609],"outofrange":[24772609]} |
||||
{"occurs":[131073,2228225,6684673,22020097,23920641],"object":[131073,1769480,1835015,1900551,1966088,2031618,2097154,2228235,2293767,2359307,2424843,2490379,2555915,2621451,2949127,3014671,3080196,3211275,3276807,3342338,3407883,3473416,3538955,3604491,3670027,3735563,3801100,3866635,3932171,3997707,4063239,4128779,4194306,4456459,4718593,5373953,6094849,6160385,6225921,6291457,7405577,7471115,7536650,7667721,7733259,7798794,7929863,7995401,8060936,8192007,8257545,8323080,10223617,10354690,11468801,11534337,11599873,11665409,12320769,12713986,12779522,12845058,12910594,15269889,21495809,21561353,21626888,21692424,21757961,21823490,21889026,21954562,22020108,22085640,22151169,22347788,22544396,22609932,22675468,22806540,23330824,23396368,23461892,23527425,23592972,23658504,23724034,23855116,23920651,23986188,24051724,24117260,24182796,24248333,24313868,24444940,24510476,24576008,24641548,24707074,24903681,24969217,25034753,25100289,25231372],"override":[196609,1114113,4653057,4915201,5111809,5308417,7405569,7471105,7536641,7602177,7667713,7733249,7798785,8519681,8716289,8781825,8847361,8912899,9109505,9175041,9240577,9306113,9371649,10616833,10747905,11337731,18874369,19202049,19267585,19333121,19398657,19595265,19660801,22151169],"options":[262145,589825,1179649,1638401,2031617,5570567,5636102,5701638,5767174,6029313,6750216,6815752,6881286,7012353,9699336,10944520,12320773,13959170,14024705,14548994,14614530,14680065,14811138,15400961,16711686,17170433,18153474,18219009,20316161,21823491,21889026,22151169,22544387,23003138,23068674,23134210,23265282,24051713,25231362],"oauth2":[1703937,4521986,12255233,21430273,21495809],"obtain":[1703937,4587522,21495809],"operations":[1769473,1835009,1900545,1966081,2228225,2359297,2424833,2490369,2555905,2621441,3014657,3211265,3407873,3473409,3538945,3604481,3670017,3735553,3801089,3866625,3932161,3997697,4128769,4456449,4653057,4915201,5111809,5308417,12320770,21561345,21626881,21692417,21757953,22020097,22347777,22544385,22609921,22675457,22806529,23396353,23592961,23855105,23920641,23986177,24051713,24117249,24182785,24248321,24313857,24444929,24510465,24641537,24772609,25165825,25231362],"one":[2752513,2818049,2883585,3473409,7208961,12320769,23003137,23068673,23265281,23920641,23986177,24772609],"overrides":[3342337,4194305,8912897,11337729,23724033,24707073],"overridden":[3473410,23920642],"overload":[5636097,5701633,5767169,6422529,6488065,6750209,6815745,7471105,7536641,7733249,7798785,7995393,8060929,8257537,8323073,8519681,8585217,8650753,8978433,9043969,9568257,9633793,9961473,10027009,10092545,10158081,10485761,10551297,11010049,11075585,11141121,11206657,11272193,11599873,11665409,11796481,11862017,11927553,11993089,12058625,12124161,12517377,12582913,12648449,12713985,12779521,12845057,12910593,12976129,13041665,13107201,13172737,13238273,13303809,13369345,13434881,13500417,13565953,13631489],"optional":[6029322,6553602,6684674,6750210,6815746,7012356,9699330,10944514,11599874,12189698,12320769,24707073],"obtained":[6029313],"option":[6422529,6488065,12320769,12582914,22085635,22216706],"omit":[11468801,11534337,11599873,11665409],"objects":[12320771,22020097,23134209,24248321],"operation":[12320769,22020097,24772618],"optiontype":[12320769,17432582,22216709],"original":[14090241,17629185,22020097],"operatio":[24772609],"outofrange":[24772609]} |
File diff suppressed because one or more lines are too long
@ -1 +1 @@ |
||||
{"qualified":[2031617,2097153,3211265,5767169,14745601,15204353,18284545,19333121,21823489,21889025,23199745,23592961,23855105],"quota":[24772609]} |
||||
{"qualified":[2031617,2097153,5767169,14745601,15204353,18284545,19333121,21823489,21889025,23199745,23855105],"quota":[24772609]} |
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue