Skip to content

Commit

Permalink
First commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
mobizt committed Mar 23, 2021
1 parent dfd7dce commit 95ed4fc
Show file tree
Hide file tree
Showing 106 changed files with 21,086 additions and 1 deletion.
12 changes: 12 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# These are supported funding model platforms

github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: ["https://www.paypal.me/mobizt"] # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
34 changes: 34 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
name: Bug report
about: Create a report to help us improve
title: BUG
labels: bug, good first issue, invalid, wontfix
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**IDE and its version:**
- Arduino, PlatformIO
- Version [e.g. 1.8.9]

**ESP8266 Arduino Core SDK version**
- Version [e.g. 2.5.1]

**Additional context**
Add any other context about the problem here.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: ENHANCEMENT
labels: enhancement
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
10 changes: 10 additions & 0 deletions .github/ISSUE_TEMPLATE/help-and-question.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
name: Help and Question
about: Usage problems and how to (should read the readme or try the examples first)
title: HELP
labels: help wanted, question
assignees: ''

---


17 changes: 17 additions & 0 deletions .github/stale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Number of days of inactivity before an issue becomes stale
daysUntilStale: 20
# Number of days of inactivity before a stale issue is closed
daysUntilClose: 5
# Issues with these labels will never be considered stale
exemptLabels:
- pinned
- security
# Label to use when marking an issue as stale
staleLabel: wontfix
# Comment to post when marking an issue as stale. Set to `false` to disable
markComment: >
This issue has been automatically marked as stale because it has not had
recent activity. It will be closed if no further activity occurs. Thank you
for your contributions.
# Comment to post when closing a stale issue. Set to `false` to disable
closeComment: false
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 mobizt

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
83 changes: 82 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,82 @@
# ESP-Signer
# Google OAuth2.0 Access Token generation Arduino Library v1.0.0


This is the library will create the OAuth2.0 access token used in the Google API's http request (REST).

The Service Account credentials e.g. project host, project id, email and private key which are available in the service account key file will be used.

This library supports ESP8266 and ESP32 MCU from Espressif.


## Tested Devices

* Wemos D1 Mini
* NodeMCU (ESP8266)
* ESP-12F
* LinkNode (ESP8266)
* Sparkfun ESP32 Thing
* NodeMCU-32
* WEMOS LOLIN32
* TTGO T8 V1.8



## Dependencies


This library required **ESP8266 or ESP32 Core SDK**.

For Arduino IDE, ESP8266 Core SDK can be installed through **Boards Manager**.

For PlatfoemIO IDE, ESP8266 Core SDK can be installed through **PIO Home** > **Platforms** > **Espressif 8266 or Espressif 32**.



## Installation


For Arduino IDE, download zip file from the repository (Github page) by select **Code** dropdown at the top of repository, select **Download ZIP**

From Arduino IDE, select menu **Sketch** -> **Include Library** -> **Add .ZIP Library...**.

Choose **ESP-Signer-main.zip** that previously downloaded.

Go to menu **Files** -> **Examples** -> **ESP-Signer-main** and choose one from examples.





## Usages


See [this](/examples) for complete usages.





## License

The MIT License (MIT)

Copyright (c) 2021 K. Suwatchai (Mobizt)


Permission is hereby granted, free of charge, to any person returning a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

90 changes: 90 additions & 0 deletions examples/Basic/Basic.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#include <Arduino.h>
#include <Arduino.h>
#if defined(ESP32)
#include <WiFi.h>
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
#endif

#include "ESPSigner.h"

#define WIFI_SSID "WiFi SSID"
#define WIFI_PASSWORD "WIFi PSK"


#define PROJECT_HOST "The project host without cheme (https://)"

/** These credentials are taken from Service Account key file (JSON)
* https://cloud.google.com/iam/docs/service-accounts
*/
#define PROJECT_ID "The project ID"
#define CLIENT_EMAIL "Client Email"
#define PRIVATE_KEY_ID "e172ba5eb712aea49938280fe3be3b9508dfbe0f"
const char PRIVATE_KEY[] PROGMEM = "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDQz8GHAQegHm9O\nz/mjEi5DsRW6o7ZtPqv8G2knDESxwesBvzbJxQI/WuVN1Lwn4cI84UFlbBS7p1eK\nE+GRJ8A+tPMa3K1ewCiDBZbiBRLullzhGfEvpPFadoqRWmWYeVrpUGsVp0ZkMWbM\nI6dIInXTT9CeX2CPlrUNzbENq10j+mkcAF7FX+UjoKmfBpTNdS44sxpFz6LbJMrX\nLqdOdGocNROZkYFrZ/UZKRqo1ZnUjpC8rW6kBTcyoonotioZxLU9VPYWEVEUGGcf\nP8ZT86+mVEldN98nUi05XpMhQbbzkVT9S+JYPJIurIx9O59sVukj1D3CBQ1txEIp\nxHFB0IXTAgMBAAECggEAT2NVhDLvh8BaeD/Y/Nc6MLFAfiOlBXbI44I2YcqnyV9d\nLl5ZAbA9sQGpYYRqfs010HihqOJFJa0zOoNhhJL048JfFQzmezoajOnQmiDsuDoB\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sJpICI0PyU1Tq9lxflw46lPXmpNZkFtKmbelVpQlH3UvwuV\nUBegcEvgBSXRPrZUCgKgHVG+\n-----END PRIVATE KEY-----\n";


SignerConfig config;

void tokenStatusCallback(TokenInfo info);

void setup()
{

Serial.begin(115200);
Serial.println();
Serial.println();

WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("Connecting to Wi-Fi");
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
delay(300);
}
Serial.println();
Serial.print("Connected with IP: ");
Serial.println(WiFi.localIP());
Serial.println();

/* Assign the project host (required) */
config.host = PROJECT_HOST;

/* Assign the sevice account credentials and private key (required) */
config.service_account.data.client_email = CLIENT_EMAIL;
config.service_account.data.project_id = PROJECT_ID;
config.service_account.data.private_key = PRIVATE_KEY;

/** Assign the API scopes (required)
* Use space or comma to separate the scope.
*/
config.signer.tokens.scope = "https://www.googleapis.com/auth/cloud-platform, https://www.googleapis.com/auth/userinfo.email";

/** Assign the callback function for token ggeneration status (optional) */
config.token_status_callback = tokenStatusCallback;

/* Create token */
Signer.begin(&config);
}

void loop()
{
delay(1000);

/* Check to status and also refresh the access token */
bool ready = Signer.tokenReady();
}

void tokenStatusCallback(TokenInfo info)
{
if (info.status == esp_signer_token_status_error)
{
Serial.printf("Token info: type = %s, status = %s\n", Signer.getTokenType(info).c_str(), Signer.getTokenStatus(info).c_str());
Serial.printf("Token error: %s\n", Signer.getTokenError(info).c_str());
}
else
{
Serial.printf("Token info: type = %s, status = %s\n", Signer.getTokenType(info).c_str(), Signer.getTokenStatus(info).c_str());
if (info.status == esp_signer_token_status_ready)
Serial.printf("Token: %s\n", Signer.accessToken().c_str());
}
}
84 changes: 84 additions & 0 deletions examples/Service_Account_from_File/Service_Account_from_File.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#include <Arduino.h>
#include <Arduino.h>
#if defined(ESP32)
#include <WiFi.h>
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
#endif

#include "ESPSigner.h"

#define WIFI_SSID "WiFi SSID"
#define WIFI_PASSWORD "WIFi PSK"

#define PROJECT_HOST "The project host without cheme (https://)"


SignerConfig config;

void tokenStatusCallback(TokenInfo info);

void setup()
{

Serial.begin(115200);
Serial.println();
Serial.println();

WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("Connecting to Wi-Fi");
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
delay(300);
}
Serial.println();
Serial.print("Connected with IP: ");
Serial.println(WiFi.localIP());
Serial.println();

/* Assign the project host (required) */
config.host = PROJECT_HOST;

/* The file systems for flash and SD/SDMMC can be changed in FS_Config.h. */

/** Assign the sevice account JSON file and the file storage type (required)
* https://cloud.google.com/iam/docs/service-accounts
*/
config.service_account.json.path = "/service_account_file.json"; //change this for your json file
config.service_account.json.storage_type = esp_signer_mem_storage_type_flash; //or esp_signer_mem_storage_type_sd

/** Assign the API scopes (required)
* Use space or comma to separate the scope.
*/
config.signer.tokens.scope = "https://www.googleapis.com/auth/cloud-platform, https://www.googleapis.com/auth/userinfo.email";

/** Assign the callback function for token ggeneration status (optional) */
config.token_status_callback = tokenStatusCallback;

/* Create token */
Signer.begin(&config);
}

void loop()
{
delay(1000);

/* Check to status and also refresh the access token */
bool ready = Signer.tokenReady();
}

void tokenStatusCallback(TokenInfo info)
{
if (info.status == esp_signer_token_status_error)
{
Serial.printf("Token info: type = %s, status = %s\n", Signer.getTokenType(info).c_str(), Signer.getTokenStatus(info).c_str());
Serial.printf("Token error: %s\n", Signer.getTokenError(info).c_str());
}
else
{
Serial.printf("Token info: type = %s, status = %s\n", Signer.getTokenType(info).c_str(), Signer.getTokenStatus(info).c_str());
if (info.status == esp_signer_token_status_ready)
Serial.printf("Token: %s\n", Signer.accessToken().c_str());
}
}
Loading

0 comments on commit 95ed4fc

Please sign in to comment.