Merge pull request #110 from murgatroid99/node_auth_info
Added Node auth example
This commit is contained in:
commit
a2da916923
|
|
@ -116,3 +116,24 @@ stub = Helloworld::Greeter::Stub.new('localhost:50051',
|
||||||
creds: creds,
|
creds: creds,
|
||||||
update_metadata: authorization.updater_proc)
|
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));
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue