-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update oauth2_bearer/glewlwyd_resource to handle client tokens
- Loading branch information
1 parent
b757381
commit 4001e0c
Showing
3 changed files
with
34 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
* | ||
* Glewlwyd OAuth2 Authorization token check | ||
* | ||
* Copyright 2016-2017 Nicolas Mora <[email protected]> | ||
* Copyright 2016-2018 Nicolas Mora <[email protected]> | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public License | ||
|
@@ -121,7 +121,7 @@ json_t * access_token_check_scope(struct _glewlwyd_resource_config * config, jso | |
} | ||
} | ||
if (json_array_size(j_scope_final_list) > 0) { | ||
j_res = json_pack("{siso}", "result", G_OK, "scope", json_copy(j_scope_final_list)); | ||
j_res = json_pack("{sisO}", "result", G_OK, "scope", j_scope_final_list); | ||
} else { | ||
j_res = json_pack("{si}", "result", G_ERROR_INSUFFICIENT_SCOPE); | ||
} | ||
|
@@ -155,14 +155,24 @@ int access_token_check_validity(struct _glewlwyd_resource_config * config, json_ | |
// Token is valid, check type and expiration date | ||
time(&now); | ||
expiration = json_integer_value(json_object_get(j_access_token, "iat")) + json_integer_value(json_object_get(j_access_token, "expires_in")); | ||
if (now < expiration && | ||
if (now < expiration && | ||
json_object_get(j_access_token, "type") != NULL && | ||
json_is_string(json_object_get(j_access_token, "type")) && | ||
json_is_string(json_object_get(j_access_token, "type"))) { | ||
if (config->accept_access_token && | ||
0 == o_strcmp("access_token", json_string_value(json_object_get(j_access_token, "type"))) && | ||
json_object_get(j_access_token, "username") != NULL && | ||
json_is_string(json_object_get(j_access_token, "username")) && | ||
json_string_length(json_object_get(j_access_token, "username")) > 0) { | ||
res = G_OK; | ||
res = G_OK; | ||
} else if (config->accept_client_token && | ||
0 == o_strcmp("client_token", json_string_value(json_object_get(j_access_token, "type"))) && | ||
json_object_get(j_access_token, "client_id") != NULL && | ||
json_is_string(json_object_get(j_access_token, "client_id")) && | ||
json_string_length(json_object_get(j_access_token, "client_id")) > 0) { | ||
res = G_OK; | ||
} else { | ||
res = G_ERROR_INVALID_REQUEST; | ||
} | ||
} else { | ||
res = G_ERROR_INVALID_REQUEST; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
* | ||
* Glewlwyd OAuth2 Authorization token check | ||
* | ||
* Copyright 2016-2017 Nicolas Mora <[email protected]> | ||
* Copyright 2016-2018 Nicolas Mora <[email protected]> | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public License | ||
|
@@ -37,11 +37,13 @@ | |
#define BODY_URL_PARAMETER "access_token" | ||
|
||
struct _glewlwyd_resource_config { | ||
int method; | ||
char * oauth_scope; | ||
char * jwt_decode_key; | ||
jwt_alg_t jwt_alg; | ||
char * realm; | ||
int method; | ||
char * oauth_scope; | ||
char * jwt_decode_key; | ||
jwt_alg_t jwt_alg; | ||
char * realm; | ||
unsigned short accept_access_token; | ||
unsigned short accept_client_token; | ||
}; | ||
|
||
int callback_check_glewlwyd_access_token (const struct _u_request * request, struct _u_response * response, void * user_data); | ||
|