Skip to content

Commit 4657b70

Browse files
authored
Fix for managed tokens (#93)
* handle managed token url containing '/token' * update news * update ver no * fixup documentation
1 parent 39bc1ca commit 4657b70

9 files changed

Lines changed: 47 additions & 65 deletions

File tree

‎DESCRIPTION‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: AzureAuth
22
Title: Authentication Services for Azure Active Directory
3-
Version: 1.3.4
3+
Version: 1.3.5
44
Authors@R: c(
55
person("Hong", "Ooi", , "hongooi73@gmail.com", role = c("aut", "cre")),
66
person("Tyler", "Littlefield", role="ctb"),
@@ -33,5 +33,6 @@ Suggests:
3333
shinyjs,
3434
AzureRMR,
3535
AzureGraph
36+
Encoding: UTF-8
3637
Roxygen: list(markdown=TRUE, r6=FALSE)
37-
RoxygenNote: 7.3.2
38+
Config/roxygen2/version: 8.1.0

‎NAMESPACE‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
# Generated by roxygen2: do not edit by hand
22

3+
S3method(build_assertion,cert_assertion)
4+
S3method(build_assertion,character)
5+
S3method(build_assertion,default)
6+
S3method(build_assertion,stored_cert)
37
S3method(decode_jwt,AzureToken)
48
S3method(decode_jwt,Token)
59
S3method(decode_jwt,character)
610
S3method(extract_jwt,AzureToken)
711
S3method(extract_jwt,Token)
812
S3method(extract_jwt,character)
13+
S3method(sign_assertion,character)
14+
S3method(sign_assertion,openssl_cert_pair)
15+
S3method(sign_assertion,stored_cert)
916
export(AzureManualToken)
1017
export(AzureR_dir)
1118
export(AzureToken)

‎NEWS.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# AzureAuth 1.3.5
2+
3+
- Fix to `get_managed_token` to handle host URLs that already have the `/token` endpoint included.
4+
15
# AzureAuth 1.3.4
26

37
- New `get_manual_token` function to create a token object from an external token string. Thanks to @falbukrek.

‎R/cert_creds.R‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,22 @@ build_assertion <- function(assertion, ...)
3939
}
4040

4141

42+
#' @export
4243
build_assertion.stored_cert <- function(assertion, ...)
4344
{
4445
build_assertion(cert_assertion(assertion), ...)
4546
}
4647

4748

49+
#' @export
4850
build_assertion.character <- function(assertion, ...)
4951
{
5052
pair <- read_cert_pair(assertion)
5153
build_assertion(cert_assertion(pair), ...)
5254
}
5355

5456

57+
#' @export
5558
build_assertion.cert_assertion <- function(assertion, tenant, app, aad_host, version, ...)
5659
{
5760
url <- httr::parse_url(aad_host)
@@ -72,6 +75,7 @@ build_assertion.cert_assertion <- function(assertion, tenant, app, aad_host, ver
7275
}
7376

7477

78+
#' @export
7579
build_assertion.default <- function(assertion, ...)
7680
{
7781
if(is.null(assertion))
@@ -86,6 +90,7 @@ sign_assertion <- function(certificate, claim, size)
8690
}
8791

8892

93+
#' @export
8994
sign_assertion.stored_cert <- function(certificate, claim, size)
9095
{
9196
kty <- certificate$policy$key_props$kty # key type determines signing alg
@@ -100,6 +105,7 @@ sign_assertion.stored_cert <- function(certificate, claim, size)
100105
}
101106

102107

108+
#' @export
103109
sign_assertion.openssl_cert_pair <- function(certificate, claim, size)
104110
{
105111
alg <- if(inherits(certificate$key, "rsa"))
@@ -115,6 +121,7 @@ sign_assertion.openssl_cert_pair <- function(certificate, claim, size)
115121
}
116122

117123

124+
#' @export
118125
sign_assertion.character <- function(certificate, claim, size)
119126
{
120127
pair <- read_cert_pair(certificate)

‎R/managed_token.R‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,9 @@
33
get_managed_token <- function(resource, token_args=list(), use_cache=NULL)
44
{
55
aad_host <- Sys.getenv("MSI_ENDPOINT", "http://169.254.169.254/metadata/identity/oauth2")
6+
7+
# deal with situation where host url string already contains '/token'
8+
aad_host <- sub("/token$", "", aad_host)
9+
610
AzureTokenManaged$new(resource, aad_host, token_args=token_args, use_cache=use_cache)
711
}

‎R/token_manual.R‎

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@
22
#'
33
#' Create an Azure token object from a pre-existing access token string. This is useful
44
#' when you have obtained a token externally (e.g., via Azure CLI, Python, or another
5-
#' authentication mechanism) and want to use it with the AzureR ecosystem.
5+
#' authentication mechanism) and want to use it with the AzureR ecosystem. Rather than
6+
#' calling the new() method directly, tokens should be created via [get_manual_token()].
67
#'
78
#' @docType class
89
#' @section Methods:
9-
#' \itemize{
10-
#' \item \code{new(token, type, tenant, resource)}: Initialize a new manual token object.
11-
#' \item \code{refresh()}: Cannot refresh a manual token; issues a warning and returns self.
12-
#' \item \code{validate()}: Checks if the token has expired based on JWT claims.
13-
#' \item \code{can_refresh()}: Returns FALSE since manual tokens cannot be refreshed.
14-
#' \item \code{cache()}: No-op; manual tokens are not cached.
15-
#' }
10+
#'
11+
#' This section documents how the methods for manual tokens differ from other token objects.
12+
#'
13+
#' - `refresh`: Manual tokens cannot be refreshed; you must create a new token object.
14+
#' - `can_refresh`: Always returns FALSE for manual tokens.
15+
#' - `cache`: Manual tokens are not cached; this method does nothing.
16+
#' - `hash`: The hash is based on the token string itself, rather than the R-level metadata.
1617
#'
1718
#' @details
1819
#' The \code{AzureManualToken} class provides a way to wrap an externally-obtained access
@@ -58,11 +59,6 @@ AzureManualToken <- R6::R6Class("AzureManualToken", inherit = AzureToken,
5859

5960
public = list(
6061

61-
#' @description Initialize a manual token from a raw access token string.
62-
#' @param token A character string containing the access token.
63-
#' @param type The token type, usually "Bearer".
64-
#' @param tenant Optional tenant ID. If NULL, extracted from JWT claims.
65-
#' @param resource Optional resource/audience. If NULL, extracted from JWT claims.
6662
initialize = function(token, type = "Bearer", tenant = NULL, resource = NULL)
6763
{
6864
if(missing(token) || is.null(token) || !is.character(token) || nchar(token) == 0)
@@ -173,30 +169,22 @@ public = list(
173169
invisible(self)
174170
},
175171

176-
#' @description Refresh the token. Manual tokens cannot be refreshed.
177-
#' @return Returns self invisibly.
178172
refresh = function()
179173
{
180174
invisible(self)
181175
},
182176

183-
#' @description Check if this token can be refreshed.
184-
#' @return Always returns FALSE for manual tokens.
185177
can_refresh = function()
186178
{
187179
FALSE
188180
},
189181

190-
#' @description Cache the token. Manual tokens are not cached.
191-
#' @return Returns NULL invisibly.
192182
cache = function()
193183
{
194184
# Do not cache manual tokens - they are managed externally
195185
invisible(NULL)
196186
},
197187

198-
#' @description Compute a hash for this token.
199-
#' @return An MD5 hash string based on the token content.
200188
hash = function()
201189
{
202190
# Hash based on the token string itself
@@ -209,7 +197,6 @@ public = list(
209197
paste(openssl::md5(msg[-(1:14)]), collapse = "")
210198
},
211199

212-
#' @description Print the token object.
213200
print = function()
214201
{
215202
cat(format_auth_header(self))

‎man/AzureManualToken.Rd‎

Lines changed: 10 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎man/AzureToken.Rd‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎man/get_azure_token.Rd‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)