Skip to content

Commit

Permalink
return status code from STS call
Browse files Browse the repository at this point in the history
- if > 500 (504 = gateway timeout)
- bump liboauth2 dependency to 1.1.1
- version 3.0.1

Signed-off-by: Hans Zandbelt <[email protected]>
  • Loading branch information
zandbelt committed Jul 3, 2019
1 parent 10cd7fb commit bf468b9
Show file tree
Hide file tree
Showing 6 changed files with 314 additions and 158 deletions.
430 changes: 287 additions & 143 deletions .cproject

Large diffs are not rendered by default.

6 changes: 0 additions & 6 deletions .project
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.cdt.autotools.core.genmakebuilderV2</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
<triggers>clean,full,incremental,</triggers>
Expand All @@ -28,6 +23,5 @@
<nature>org.eclipse.cdt.core.ccnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
<nature>org.eclipse.cdt.autotools.core.autotoolsNatureV2</nature>
</natures>
</projectDescription>
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
07/03/2019
- return status code from STS call: if > 500 (504 = gateway timeout)
- bump liboauth2 dependency to 1.1.1
- version 3.0.1
6 changes: 3 additions & 3 deletions configure.ac
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
AC_INIT([ngx_sts_module],[3.0.0],[[email protected]])
AC_INIT([ngx_sts_module],[3.0.1],[[email protected]])

AM_INIT_AUTOMAKE([foreign no-define subdir-objects])
AC_CONFIG_MACRO_DIRS([m4])
Expand All @@ -25,11 +25,11 @@ AM_CONDITIONAL(HAVE_NGINX, [test x"$have_nginx" = "xyes"])
AC_SUBST(NGINX_CFLAGS)
AC_SUBST(NGINX_LIBS)

PKG_CHECK_MODULES(OAUTH2, [liboauth2 >= 1.0.0])
PKG_CHECK_MODULES(OAUTH2, [liboauth2 >= 1.1.1])
AC_SUBST(OAUTH2_CFLAGS)
AC_SUBST(OAUTH2_LIBS)

PKG_CHECK_MODULES(OAUTH2_NGINX, [liboauth2_nginx >= 1.0.0])
PKG_CHECK_MODULES(OAUTH2_NGINX, [liboauth2_nginx >= 1.1.1])
AC_SUBST(OAUTH2_NGINX_CFLAGS)
AC_SUBST(OAUTH2_NGINX_LIBS)

Expand Down
2 changes: 1 addition & 1 deletion src/liboauth2-sts
24 changes: 19 additions & 5 deletions src/ngx_sts_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,12 +303,13 @@ static ngx_int_t ngx_sts_post_config(ngx_conf_t *cf)

static ngx_int_t ngx_sts_handler(ngx_http_request_t *r)
{
ngx_int_t rv = NGX_DECLINED;
ngx_int_t rv = NGX_ERROR;
bool rc = false;
oauth2_nginx_request_context_t *ctx = NULL;
ngx_sts_config *cfg = NULL;
ngx_str_t ngx_source_token;
char *source_token = NULL, *target_token = NULL;
oauth2_http_status_code_t status_code = 0;

if (r != r->main)
goto end;
Expand Down Expand Up @@ -352,19 +353,32 @@ static ngx_int_t ngx_sts_handler(ngx_http_request_t *r)
oauth2_debug(ctx->log, "enter: source_token=%s, initial_request=%d",
source_token, (r != r->main));

rc = sts_handler(ctx->log, cfg->cfg, source_token, &target_token);
rc = sts_handler(ctx->log, cfg->cfg, source_token, &target_token,
&status_code);

oauth2_debug(ctx->log, "target_token=%s (rc=%d)",
target_token ? target_token : "(null)", rc);

oauth2_debug(ctx->log, "target_token=%s (rc=%d)", target_token, rc);
if (rc == false) {
if (status_code < 500) {
r->headers_out.status = NGX_HTTP_UNAUTHORIZED;
} else {
r->headers_out.status = (ngx_uint_t)status_code;
}
goto end;
}

if (target_token == NULL)
if (target_token == NULL) {
rv = NGX_DONE;
goto end;
}

cfg->target_token.len = strlen(target_token);
cfg->target_token.data = ngx_palloc(r->pool, cfg->target_token.len);
ngx_memcpy(cfg->target_token.data, (unsigned char *)target_token,
cfg->target_token.len);

rv = rc ? NGX_OK : NGX_ERROR;
rv = NGX_OK;

end:

Expand Down

0 comments on commit bf468b9

Please sign in to comment.