Skip to content

Commit 697044a

Browse files
committed
Add FirebaseApp::getTokenType and update examples
1 parent dbb6693 commit 697044a

File tree

21 files changed

+299
-29
lines changed

21 files changed

+299
-29
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
[![GitHub Sponsors](https://img.shields.io/github/sponsors/mobizt?logo=github)](https://github.com/sponsors/mobizt)
88

9-
Revision `2025-02-13`
9+
Revision `2025-02-16`
1010

1111
## Table of Contents
1212

@@ -3066,11 +3066,11 @@ Current sponsors
30663066

30673067

30683068
<a href="https://github.com/Jagakatt"><img src="https://github.com/Jagakatt.png" width="30" height="30" alt="@Jagakatt"></a>
3069-
<a href="#sponsors"><img src="https://avatars.githubusercontent.com/u/166620797?s=35&v=4" width="30" height="30" alt="private sponsor"></a> <a href="https://github.com/siz0001"><img src="https://avatars.githubusercontent.com/u/42665078?s=60&v=4" width="30" height="30" alt="@siz0001"></a>
3069+
<a href="#sponsors"><img src="https://avatars.githubusercontent.com/u/166620797?s=35&v=4" width="30" height="30" alt="private sponsor"></a>
30703070

30713071
Past sponsors
30723072

3073-
<img src="https://avatars.githubusercontent.com/u/5763108?s=60&amp;v=4" width="30" height="30" alt="past_sponsor"> <img src="https://avatars.githubusercontent.com/u/57544850?s=60&amp;v=4" width="30" height="30" alt="past_sponsor"> <img src="https://avatars.githubusercontent.com/u/63749581?s=60&amp;v=4" width="30" height="30" alt="past_sponsor"> <img src="https://avatars.githubusercontent.com/u/83292822?s=60&amp;v=4" width="30" height="30" alt="past_sponsor"> <img src="https://avatars.githubusercontent.com/u/31892707?s=60&amp;v=4" width="30" height="30" alt="past_sponsor"> <img src="https://avatars.githubusercontent.com/u/96478986?s=60&amp;v=4" width="30" height="30" alt="past_sponsor">
3073+
<img src="https://avatars.githubusercontent.com/u/5763108?s=60&amp;v=4" width="30" height="30" alt="past_sponsor"> <img src="https://avatars.githubusercontent.com/u/57544850?s=60&amp;v=4" width="30" height="30" alt="past_sponsor"> <img src="https://avatars.githubusercontent.com/u/63749581?s=60&amp;v=4" width="30" height="30" alt="past_sponsor"> <img src="https://avatars.githubusercontent.com/u/83292822?s=60&amp;v=4" width="30" height="30" alt="past_sponsor"> <img src="https://avatars.githubusercontent.com/u/31892707?s=60&amp;v=4" width="30" height="30" alt="past_sponsor"> <img src="https://avatars.githubusercontent.com/u/96478986?s=60&amp;v=4" width="30" height="30" alt="past_sponsor"> <a href="https://github.com/siz0001"><img src="https://avatars.githubusercontent.com/u/42665078?s=60&v=4" width="30" height="30" alt="@siz0001"></a>
30743074

30753075
### Buy Me a Coffee
30763076

examples/App/AppInitialization/Async/Callback/CustomAuth/CustomAuth.ino

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
* <scope> - The OAuth scopes.
3737
* <claims> - The OAuth claims. For more details about claims, please visit https://firebase.google.com/docs/auth/admin/custom-claims.
3838
* <expire> - The expiry period in seconds (less than 3600), 3300 is the default value.
39-
*
39+
*
4040
* See examples/RealtimeDatabase/Sync/CustomClaims/CustomClaims.ino for how it can work with security rules for database access control.
4141
*
4242
* 3.------------------------
@@ -124,6 +124,8 @@ using AsyncClient = AsyncClientClass;
124124

125125
AsyncClient aClient(ssl_client, getNetwork(network));
126126

127+
bool taskComplete = false;
128+
127129
void setup()
128130
{
129131
Serial.begin(115200);
@@ -180,6 +182,21 @@ void loop()
180182

181183
// To get the authentication time to live in seconds before expired.
182184
// app.ttl();
185+
186+
if (app.ready() && !taskComplete)
187+
{
188+
taskComplete = true;
189+
Firebase.printf("Auth Token: %s\n", app.getToken().c_str());
190+
firebase_token_type type = app.getTokenType();
191+
if (type == token_type_access)
192+
Serial.println("Token Type: access token");
193+
else if (type == token_type_id)
194+
Serial.println("Token Type: ID token");
195+
else if (type == token_type_legacy)
196+
Serial.println("Token Type: legacy token");
197+
else if (type == token_type_no)
198+
Serial.println("Token Type: no token");
199+
}
183200
}
184201

185202
void timeStatusCB(uint32_t &ts)

examples/App/AppInitialization/Async/Callback/CustomAuthFile/CustomAuthFile.ino

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* <scope> - The OAuth scopes.
3838
* <claims> - The OAuth claims. For more details about claims, please visit https://firebase.google.com/docs/auth/admin/custom-claims.
3939
* <expire> - The expiry period in seconds (less than 3600), 3300 is the default value.
40-
*
40+
*
4141
* See examples/RealtimeDatabase/Sync/CustomClaims/CustomClaims.ino for how it can work with security rules for database access control.
4242
*
4343
* 3.------------------------
@@ -144,6 +144,8 @@ using AsyncClient = AsyncClientClass;
144144

145145
AsyncClient aClient(ssl_client, getNetwork(network));
146146

147+
bool taskComplete = false;
148+
147149
void setup()
148150
{
149151
Serial.begin(115200);
@@ -203,6 +205,21 @@ void loop()
203205

204206
// To get the authentication time to live in seconds before expired.
205207
// app.ttl();
208+
209+
if (app.ready() && !taskComplete)
210+
{
211+
taskComplete = true;
212+
Firebase.printf("Auth Token: %s\n", app.getToken().c_str());
213+
firebase_token_type type = app.getTokenType();
214+
if (type == token_type_access)
215+
Serial.println("Type: access token");
216+
else if (type == token_type_id)
217+
Serial.println("Type: ID token");
218+
else if (type == token_type_legacy)
219+
Serial.println("Type: legacy token");
220+
else if (type == token_type_no)
221+
Serial.println("Type: no token");
222+
}
206223
}
207224

208225
void timeStatusCB(uint32_t &ts)

examples/App/AppInitialization/Async/Callback/ServiceAuth/ServiceAuth.ino

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* ABOUT:
33
*
44
* The bare minimum non-blocking (async) example for Firebase OAuth2.0 authentication.
5-
*
5+
*
66
* This example requires the service account credentials that obtains from the JSON key file.
77
*
88
* This example uses the DefaultNetwork class for network interface configuration.
@@ -32,7 +32,7 @@
3232
* <project_id> - The service account project ID.
3333
* <private_key> - The service account private key.
3434
* <expire> - The expiry period in seconds (less than 3600), 3300 is the default value.
35-
*
35+
*
3636
* 3.------------------------
3737
*
3838
* ServiceAuth::ServiceAuth(<timestamp>, <client_email>, <project_id>, <private_key>, <expire>);
@@ -113,6 +113,8 @@ using AsyncClient = AsyncClientClass;
113113

114114
AsyncClient aClient(ssl_client, getNetwork(network));
115115

116+
bool taskComplete = false;
117+
116118
void setup()
117119
{
118120
Serial.begin(115200);
@@ -159,6 +161,21 @@ void loop()
159161

160162
// To get the authentication time to live in seconds before expired.
161163
// app.ttl();
164+
165+
if (app.ready() && !taskComplete)
166+
{
167+
taskComplete = true;
168+
Firebase.printf("Auth Token: %s\n", app.getToken().c_str());
169+
firebase_token_type type = app.getTokenType();
170+
if (type == token_type_access)
171+
Serial.println("Token Type: access token");
172+
else if (type == token_type_id)
173+
Serial.println("Token Type: ID token");
174+
else if (type == token_type_legacy)
175+
Serial.println("Token Type: legacy token");
176+
else if (type == token_type_no)
177+
Serial.println("Token Type: no token");
178+
}
162179
}
163180

164181
void timeStatusCB(uint32_t &ts)

examples/App/AppInitialization/Async/Callback/ServiceAuthFile/ServiceAuthFile.ino

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* ABOUT:
33
*
44
* The bare minimum non-blocking (async) example for Firebase OAuth2.0 authentication.
5-
*
5+
*
66
* The service account JSON key file path should be set via FileConfig.
77
*
88
* This example uses the DefaultNetwork class for network interface configuration.
@@ -30,7 +30,7 @@
3030
* <TimeStatusCallback> - The time status callback that provide the UNIX timestamp value used for JWT token signing.
3131
* <file_config_data> - The filesystem data (file_config_data) obtained from FileConfig class object of service account key file.
3232
* <expire> - The expiry period in seconds (less than 3600), 3300 is the default value.
33-
*
33+
*
3434
* 3.------------------------
3535
*
3636
* ServiceAuth::ServiceAuth(<timestamp>, <file_config_data>, <expire>);
@@ -127,6 +127,8 @@ using AsyncClient = AsyncClientClass;
127127

128128
AsyncClient aClient(ssl_client, getNetwork(network));
129129

130+
bool taskComplete = false;
131+
130132
void setup()
131133
{
132134
Serial.begin(115200);
@@ -177,6 +179,21 @@ void loop()
177179

178180
// To get the authentication time to live in seconds before expired.
179181
// app.ttl();
182+
183+
if (app.ready() && !taskComplete)
184+
{
185+
taskComplete = true;
186+
Firebase.printf("Auth Token: %s\n", app.getToken().c_str());
187+
firebase_token_type type = app.getTokenType();
188+
if (type == token_type_access)
189+
Serial.println("Token Type: access token");
190+
else if (type == token_type_id)
191+
Serial.println("Token Type: ID token");
192+
else if (type == token_type_legacy)
193+
Serial.println("Token Type: legacy token");
194+
else if (type == token_type_no)
195+
Serial.println("Token Type: no token");
196+
}
180197
}
181198

182199
void timeStatusCB(uint32_t &ts)

examples/App/AppInitialization/Async/Callback/UserAuth/UserAuth.ino

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,15 @@ void loop()
150150
Firebase.printf("User UID: %s\n", app.getUid().c_str());
151151
Firebase.printf("Auth Token: %s\n", app.getToken().c_str());
152152
Firebase.printf("Refresh Token: %s\n", app.getRefreshToken().c_str());
153+
firebase_token_type type = app.getTokenType();
154+
if (type == token_type_access)
155+
Serial.println("Token Type: access token");
156+
else if (type == token_type_id)
157+
Serial.println("Token Type: ID token");
158+
else if (type == token_type_legacy)
159+
Serial.println("Token Type: legacy token");
160+
else if (type == token_type_no)
161+
Serial.println("Token Type: no token");
153162
}
154163
}
155164

examples/App/AppInitialization/Async/NoCallback/CustomAuth/CustomAuth.ino

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
* <user_id> - The unique identifier of the signed-in user must be a string, between 1-128 characters long, inclusive. Shorter uids offer better performance.
3636
* <claims> - Optional custom claims to include in the Security Rules auth / request.auth variables. For more details about claims, please visit https://firebase.google.com/docs/auth/admin/custom-claims.
3737
* <expire> - The expiry period in seconds (less than 3600), 3300 is the default value.
38-
*
38+
*
3939
* See examples/RealtimeDatabase/Sync/CustomClaims/CustomClaims.ino for how it can work with security rules for database access control.
4040
*
4141
* NOTE:
@@ -110,6 +110,8 @@ AsyncClient aClient(ssl_client, getNetwork(network));
110110

111111
AsyncResult aResult_no_callback;
112112

113+
bool taskComplete = false;
114+
113115
void setup()
114116
{
115117
Serial.begin(115200);
@@ -166,6 +168,21 @@ void loop()
166168
// To get the authentication time to live in seconds before expired.
167169
// app.ttl();
168170

171+
if (app.ready() && !taskComplete)
172+
{
173+
taskComplete = true;
174+
Firebase.printf("Auth Token: %s\n", app.getToken().c_str());
175+
firebase_token_type type = app.getTokenType();
176+
if (type == token_type_access)
177+
Serial.println("Token Type: access token");
178+
else if (type == token_type_id)
179+
Serial.println("Token Type: ID token");
180+
else if (type == token_type_legacy)
181+
Serial.println("Token Type: legacy token");
182+
else if (type == token_type_no)
183+
Serial.println("Token Type: no token");
184+
}
185+
169186
printResult(aResult_no_callback);
170187
}
171188

examples/App/AppInitialization/Async/NoCallback/CustomAuthFile/CustomAuthFile.ino

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
* <user_id> - The unique identifier of the signed-in user must be a string, between 1-128 characters long, inclusive. Shorter uids offer better performance.
3737
* <claims> - Optional custom claims to include in the Security Rules auth / request.auth variables. For more details about claims, please visit https://firebase.google.com/docs/auth/admin/custom-claims.
3838
* <expire> - The expiry period in seconds (less than 3600), 3300 is the default value.
39-
*
39+
*
4040
* See examples/RealtimeDatabase/Sync/CustomClaims/CustomClaims.ino for how it can work with security rules for database access control.
4141
*
4242
* NOTE:
@@ -129,6 +129,8 @@ AsyncClient aClient(ssl_client, getNetwork(network));
129129

130130
AsyncResult aResult_no_callback;
131131

132+
bool taskComplete = false;
133+
132134
void setup()
133135
{
134136
Serial.begin(115200);
@@ -189,6 +191,21 @@ void loop()
189191
// To get the authentication time to live in seconds before expired.
190192
// app.ttl();
191193

194+
if (app.ready() && !taskComplete)
195+
{
196+
taskComplete = true;
197+
Firebase.printf("Auth Token: %s\n", app.getToken().c_str());
198+
firebase_token_type type = app.getTokenType();
199+
if (type == token_type_access)
200+
Serial.println("Token Type: access token");
201+
else if (type == token_type_id)
202+
Serial.println("Token Type: ID token");
203+
else if (type == token_type_legacy)
204+
Serial.println("Token Type: legacy token");
205+
else if (type == token_type_no)
206+
Serial.println("Token Type: no token");
207+
}
208+
192209
printResult(aResult_no_callback);
193210
}
194211

examples/App/AppInitialization/Async/NoCallback/ServiceAuth/ServiceAuth.ino

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* ABOUT:
33
*
44
* The bare minimum non-blocking (async) example for Firebase OAuth2.0 authentication.
5-
*
5+
*
66
* This example requires the service account credentials that obtains from the JSON key file.
77
*
88
* This example uses the DefaultNetwork class for network interface configuration.
@@ -103,6 +103,8 @@ AsyncClient aClient(ssl_client, getNetwork(network));
103103

104104
AsyncResult aResult_no_callback;
105105

106+
bool taskComplete = false;
107+
106108
void setup()
107109
{
108110
Serial.begin(115200);
@@ -150,6 +152,21 @@ void loop()
150152
// To get the authentication time to live in seconds before expired.
151153
// app.ttl();
152154

155+
if (app.ready() && !taskComplete)
156+
{
157+
taskComplete = true;
158+
Firebase.printf("Auth Token: %s\n", app.getToken().c_str());
159+
firebase_token_type type = app.getTokenType();
160+
if (type == token_type_access)
161+
Serial.println("Token Type: access token");
162+
else if (type == token_type_id)
163+
Serial.println("Token Type: ID token");
164+
else if (type == token_type_legacy)
165+
Serial.println("Token Type: legacy token");
166+
else if (type == token_type_no)
167+
Serial.println("Token Type: no token");
168+
}
169+
153170
printResult(aResult_no_callback);
154171
}
155172

examples/App/AppInitialization/Async/NoCallback/ServiceAuthFile/ServiceAuthFile.ino

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* ABOUT:
33
*
44
* The bare minimum non-blocking (async) example for Firebase OAuth2.0 authentication.
5-
*
5+
*
66
* The service account JSON key file path should be set via FileConfig.
77
*
88
* This example uses the DefaultNetwork class for network interface configuration.
@@ -119,6 +119,8 @@ AsyncClient aClient(ssl_client, getNetwork(network));
119119

120120
AsyncResult aResult_no_callback;
121121

122+
bool taskComplete = false;
123+
122124
void setup()
123125
{
124126
Serial.begin(115200);
@@ -170,6 +172,21 @@ void loop()
170172
// To get the authentication time to live in seconds before expired.
171173
// app.ttl();
172174

175+
if (app.ready() && !taskComplete)
176+
{
177+
taskComplete = true;
178+
Firebase.printf("Auth Token: %s\n", app.getToken().c_str());
179+
firebase_token_type type = app.getTokenType();
180+
if (type == token_type_access)
181+
Serial.println("Token Type: access token");
182+
else if (type == token_type_id)
183+
Serial.println("Token Type: ID token");
184+
else if (type == token_type_legacy)
185+
Serial.println("Token Type: legacy token");
186+
else if (type == token_type_no)
187+
Serial.println("Token Type: no token");
188+
}
189+
173190
printResult(aResult_no_callback);
174191
}
175192

examples/App/AppInitialization/Async/NoCallback/UserAuth/UserAuth.ino

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,15 @@ void loop()
150150
Firebase.printf("User UID: %s\n", app.getUid().c_str());
151151
Firebase.printf("Auth Token: %s\n", app.getToken().c_str());
152152
Firebase.printf("Refresh Token: %s\n", app.getRefreshToken().c_str());
153+
firebase_token_type type = app.getTokenType();
154+
if (type == token_type_access)
155+
Serial.println("Token Type: access token");
156+
else if (type == token_type_id)
157+
Serial.println("Token Type: ID token");
158+
else if (type == token_type_legacy)
159+
Serial.println("Token Type: legacy token");
160+
else if (type == token_type_no)
161+
Serial.println("Token Type: no token");
153162
}
154163

155164
printResult(aResult_no_callback);

0 commit comments

Comments
 (0)