Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Grpc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tci-gateway-module
Grpc
Commits
777fee23
Commit
777fee23
authored
9 years ago
by
Jorge Canizales
Browse files
Options
Downloads
Patches
Plain Diff
Add Objective-C sections to the common auth README
parent
3508c9a5
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
grpc-auth-support.md
+56
-0
56 additions, 0 deletions
grpc-auth-support.md
with
56 additions
and
0 deletions
grpc-auth-support.md
+
56
−
0
View file @
777fee23
...
...
@@ -114,6 +114,22 @@ 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.
```
###Authenticating with Google (Ruby)
```
ruby
# Base case - No encryption/authorization
...
...
@@ -174,3 +190,43 @@ if (authorization.IsCreateScopedRequired)
var
client
=
new
Greeter
.
GreeterClient
(
channel
,
new
StubConfiguration
(
OAuth2InterceptorFactory
.
Create
(
credential
)));
```
###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 <gRPC/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
=
[
NSMutableDictionary
dictionaryWithDictionary
:
@{
@"Authorization"
:
[
@"Bearer "
stringByAppendingString
:
accessToken
]}];
// Start the RPC.
[
call
start
];
```
You can see a working example app, with a more detailed explanation,
[
here
](
https://github.com/grpc/grpc-common/tree/master/objective-c/auth_sample
)
.
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment