Skip to content

Commit

Permalink
fix authentication for web
Browse files Browse the repository at this point in the history
  • Loading branch information
zefanjajobse committed Sep 25, 2022
1 parent 05d889c commit 5420c4f
Show file tree
Hide file tree
Showing 17 changed files with 544 additions and 468 deletions.
24 changes: 20 additions & 4 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,37 @@ const call = communityGames.getPlayground(request, metadata,
## python
for python you can use the 'sonora' package to do grpc-web
```py
import asyncio
import sonora.aio
import sys
from proto import communitygames_pb2, communitygames_pb2_grpc
from bfportal_grpc import communitygames_pb2, communitygames_pb2_grpc, access_token, authentication_pb2, authentication_pb2_grpc

async def main():
cookie = access_token.Cookie(sid="", remid="")
token = await access_token.getBf2042GatewaySession(cookie)

async with sonora.aio.insecure_web_channel(
f"https://kingston-prod-wgw-envoy.ops.dice.se"
) as channel:
stub = authentication_pb2_grpc.AuthenticationStub(channel)
auth_response: authentication_pb2.AuthResponse = await stub.viaAuthCode(authentication_pb2.AuthRequest(platform=1, authCode=token, redirectUri='https://portal.battlefield.com/'), metadata=(
('x-dice-tenancy', 'prod_default-prod_default-kingston-common'),
('x-gateway-session-id', 'web-c6b312c9-2520-4fde-958d-60ae71840a65'),
('x-grpc-web', '1'),
('x-user-agent', 'grpc-web-javascript/0.1')
))

stub = communitygames_pb2_grpc.CommunityGamesStub(channel)
response: communitygames_pb2.PlaygroundInfoResponse = await stub.getPlayground(communitygames_pb2.GetPlaygroundRequest(playgroundId="10992a10-461a-11ec-8de0-d9f491f92236"), metadata=(
('x-dice-tenancy', 'prod_default-prod_default-kingston-common'),
('x-gateway-session-id', 'web-c6b312c9-2520-4fde-958d-60ae71840a65'),
('x-gateway-session-id', auth_response.sessionId),
('x-grpc-web', '1'),
('x-user-agent', 'grpc-web-javascript/0.1')
))

print(response.playground.originalPlayground.name)

if __name__ == "__main__":
asyncio.run(main())
```
### current build method from proto to javascript via python
Expand All @@ -115,6 +131,6 @@ python package used: https://github.com/romnn/proto-compile
### Pushing your changes
package versions can be made with `npm run build` and `npm version patch` `git push --tags origin main` to release.
for python patch with `npm run build:python`, `npm run python:setimports` and `poetry build`.
example library used: https://github.com/tomchen/example-typescript-package
1 change: 1 addition & 0 deletions bfportal_grpc/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .proto import authentication_pb2_grpc, authentication_pb2, communitygames_pb2_grpc, communitygames_pb2, localization_pb2_grpc, localization_pb2, reporting_pb2_grpc, reporting_pb2
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
class Cookie:
sid: str
remid: str

def __init__(self, sid: str, remid: str):
self.sid = sid
self.remid = remid

async def getBf2042GatewaySession(cookie: Cookie):
async def getBf2042GatewaySession(cookie: Cookie) -> str:
async with aiohttp.ClientSession() as session:
url = "https://accounts.ea.com/connect/auth?client_id=KINGSTON_COMP_APP&locale=en_US&redirect_uri=https%3A%2F%2Fportal.battlefield.com%2F&response_type=code"
headers = {
Expand Down
File renamed without changes.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"""Client and server classes corresponding to protobuf-defined services."""
import grpc

from proto import authentication_pb2 as proto_dot_authentication__pb2
from . import authentication_pb2 as authentication__pb2


class ClientAuthenticationStub(object):
class AuthenticationStub(object):
"""Missing associated documentation comment in .proto file."""

def __init__(self, channel):
Expand All @@ -15,18 +15,18 @@ def __init__(self, channel):
channel: A grpc.Channel.
"""
self.viaAuthCode = channel.unary_unary(
'/web.authentication.ClientAuthentication/viaAuthCode',
request_serializer=proto_dot_authentication__pb2.AuthRequest.SerializeToString,
response_deserializer=proto_dot_authentication__pb2.AuthResponse.FromString,
'/web.authentication.Authentication/viaAuthCode',
request_serializer=authentication__pb2.AuthRequest.SerializeToString,
response_deserializer=authentication__pb2.AuthResponse.FromString,
)
self.logout = channel.unary_unary(
'/web.authentication.ClientAuthentication/logout',
request_serializer=proto_dot_authentication__pb2.Empty.SerializeToString,
response_deserializer=proto_dot_authentication__pb2.Empty.FromString,
'/web.authentication.Authentication/logout',
request_serializer=authentication__pb2.Empty.SerializeToString,
response_deserializer=authentication__pb2.Empty.FromString,
)


class ClientAuthenticationServicer(object):
class AuthenticationServicer(object):
"""Missing associated documentation comment in .proto file."""

def viaAuthCode(self, request, context):
Expand All @@ -42,26 +42,26 @@ def logout(self, request, context):
raise NotImplementedError('Method not implemented!')


def add_ClientAuthenticationServicer_to_server(servicer, server):
def add_AuthenticationServicer_to_server(servicer, server):
rpc_method_handlers = {
'viaAuthCode': grpc.unary_unary_rpc_method_handler(
servicer.viaAuthCode,
request_deserializer=proto_dot_authentication__pb2.AuthRequest.FromString,
response_serializer=proto_dot_authentication__pb2.AuthResponse.SerializeToString,
request_deserializer=authentication__pb2.AuthRequest.FromString,
response_serializer=authentication__pb2.AuthResponse.SerializeToString,
),
'logout': grpc.unary_unary_rpc_method_handler(
servicer.logout,
request_deserializer=proto_dot_authentication__pb2.Empty.FromString,
response_serializer=proto_dot_authentication__pb2.Empty.SerializeToString,
request_deserializer=authentication__pb2.Empty.FromString,
response_serializer=authentication__pb2.Empty.SerializeToString,
),
}
generic_handler = grpc.method_handlers_generic_handler(
'web.authentication.ClientAuthentication', rpc_method_handlers)
'web.authentication.Authentication', rpc_method_handlers)
server.add_generic_rpc_handlers((generic_handler,))


# This class is part of an EXPERIMENTAL API.
class ClientAuthentication(object):
class Authentication(object):
"""Missing associated documentation comment in .proto file."""

@staticmethod
Expand All @@ -75,9 +75,9 @@ def viaAuthCode(request,
wait_for_ready=None,
timeout=None,
metadata=None):
return grpc.experimental.unary_unary(request, target, '/web.authentication.ClientAuthentication/viaAuthCode',
proto_dot_authentication__pb2.AuthRequest.SerializeToString,
proto_dot_authentication__pb2.AuthResponse.FromString,
return grpc.experimental.unary_unary(request, target, '/web.authentication.Authentication/viaAuthCode',
authentication__pb2.AuthRequest.SerializeToString,
authentication__pb2.AuthResponse.FromString,
options, channel_credentials,
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)

Expand All @@ -92,8 +92,8 @@ def logout(request,
wait_for_ready=None,
timeout=None,
metadata=None):
return grpc.experimental.unary_unary(request, target, '/web.authentication.ClientAuthentication/logout',
proto_dot_authentication__pb2.Empty.SerializeToString,
proto_dot_authentication__pb2.Empty.FromString,
return grpc.experimental.unary_unary(request, target, '/web.authentication.Authentication/logout',
authentication__pb2.Empty.SerializeToString,
authentication__pb2.Empty.FromString,
options, channel_credentials,
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)

Large diffs are not rendered by default.

Loading

0 comments on commit 5420c4f

Please sign in to comment.