Skip to content

Commit

Permalink
Google OAuth 2.0 From ServiceFile
Browse files Browse the repository at this point in the history
  • Loading branch information
pankajsoni19 committed Jun 10, 2020
1 parent c8be2b2 commit 51bb4f3
Show file tree
Hide file tree
Showing 14 changed files with 2,275 additions and 953 deletions.
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

.eunit
deps
*.o
*.beam
*.plt
erl_crash.dump
ebin
rel/example_project
.concrete/DEV_MODE
.rebar
.erlang.mk
_rel
fcm.d
relx
18 changes: 15 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
PROJECT = oauth2_s2s
DEPS = jsx
include erlang.mk
PROJECT = google_oauth
PROJECT_VERSION = $(shell head -n 1 relx.config | awk '{split($$0, a, "\""); print a[2]}')

# app:: rebar.config
LOCAL_DEPS = inets crypto public_key ssl

DEPS = lager jsx base64url

dep_lager = git https://github.com/erlang-lager/lager 3.8.0
dep_jsx = git https://github.com/talentdeficit/jsx.git v2.10.0
dep_base64url = git https://github.com/dvv/base64url.git 1.0.1

include erlang.mk

ERLC_COMPILE_OPTS= +'{parse_transform, lager_transform}'
ERLC_OPTS += $(ERLC_COMPILE_OPTS)
TEST_ERLC_OPTS += $(ERLC_COMPILE_OPTS)
86 changes: 53 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,53 @@
#### Erlang Google OAuth 2.0 API client for Server to Server Applications. This application will get a new access token for every one hour.


#####How to get the RSA Private Key file before running the application
- Reference https://developers.google.com/identity/protocols/OAuth2ServiceAccount
- After downloading the privatekey.p12 file enter the following 2 commands to convert in to RSA Private Key

openssl pkcs12 -in privatekey.p12 -out priv/temp/key-enc.pem -nodes
openssl rsa -in priv/temp/key-enc.pem -out priv/temp/RSA_Key.pem
- Give the path of this RSA_KEY.pem in the RSA_KEY_PATH Macro in "oauth2_s2s.erl" module.
- Enter the ISS in the config file and feel free to change other values before running


##### how to run the application
- git clone [email protected]:RajuC/Google_OAuth_2.0.git
- cd Google_OAuth_2.0/
- make
- erl -pa ebin/ deps/*/ebin -s oauth2_s2s -config config/sys.config

- 1> oauth2_s2s:get_access_token().

[{<<"access_token">>,
<<"ya29.LwL5_tv6bmaZyqzCm8-LiEA27dUi5UNps5ULvVgOdD-qXvZzxKCvQicModZyqn0r6g">>},
{<<"token_type">>,<<"Bearer">>},
{<<"expires_in">>,3600}]


- 2> oauth2_s2s:get_access_token(<<"https://www.googleapis.com/auth/devstorage.full_control">>).

[{<<"access_token">>,
<<"ya29.LwJyfO4raybzP5bzDyqIf6lPHjc8rMZeZuxxjGWLy5BMw1L6PzgSvtW54fIg6jbtb">>},
{<<"token_type">>,<<"Bearer">>},
{<<"expires_in">>,3600}]
#### Erlang Google OAuth 2.0 API client to generate API token for Google S2S requests

### How to compile:

`google_oauth` uses `erlang.mk` as make system. To compile

```
$ make
```

To generate release

```
$ make rel
```

### How to use with rebar:

You can use `google_oauth` as a dependency in your rebar.config:

```
{deps , [
{google_oauth, ".*", {git, "https://github.com/pankajsoni19/google_oauth.git", {tag, "1.0.0"}}}
]}.
```

### How to run the application fcm-erlang:

`make rel` will create a release under `_rel/google_oauth` directory.

```
$ cd _rel/google_oauth
$ bin/google_oauth console
```

### Request Token

```
{ok, Result} = google_oauth:get_access_token("service_account_file_path.json", SCOPE)
Result =
#{
access_token => binary()
expires_in => integer() :: seconds, :: < 3600
token_type => binary() :: <<"Bearer">>
}
```

for push notification

```
google_oauth:get_access_token("service_account_file_path.json", <<"https://www.googleapis.com/auth/firebase.messaging">>)
```
13 changes: 0 additions & 13 deletions config/sys.config

This file was deleted.

Loading

0 comments on commit 51bb4f3

Please sign in to comment.