Skip to content

Commit

Permalink
Support for audience param
Browse files Browse the repository at this point in the history
Added tests
  • Loading branch information
cocojoe committed Dec 2, 2016
1 parent fb43036 commit 7b83b28
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Auth0/SafariWebAuth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ class SafariWebAuth: WebAuth {
return self.responseType([.token])
}

func audience(_ audience: String) -> Self {
self.parameters["audience"] = audience
return self
}

func start(_ callback: @escaping (Result<Credentials>) -> ()) {
guard
let redirectURL = self.redirectURL
Expand Down
6 changes: 6 additions & 0 deletions Auth0/WebAuth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ public protocol WebAuth: Trackable, Loggable {
/// - Returns: the same WebAuth instance to allow method chaining
func nonce(_ nonce: String) -> Self

/// The application that is the intended target of the token
///
/// - Parameter audience: an audience value like: `https://someapi.com/api`
/// - Returns: the same WebAuth instance to allow method chaining
func audience(_ audience: String) -> Self

/**
Change the default grant used for auth from `code` (w/PKCE) to `token` (implicit grant)
Expand Down
32 changes: 32 additions & 0 deletions Auth0Tests/WebAuthSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,38 @@ class WebAuthSpec: QuickSpec {
"query": defaultQuery(withParameters: ["nonce": "abc1234", "response_type" : "id_token"]),
]
}

itBehavesLike(ValidAuthorizeURLExample) {
var newDefaults = defaults
newDefaults["audience"] = "https://wwww.google.com"
return [
"url": newWebAuth().buildAuthorizeURL(withRedirectURL: RedirectURL, defaults: newDefaults),
"domain": Domain,
"query": defaultQuery(withParameters: ["audience": "https://wwww.google.com"]),
]
}

itBehavesLike(ValidAuthorizeURLExample) {
var newDefaults = defaults
newDefaults["audience"] = "https://wwww.google.com"
return [
"url": newWebAuth()
.audience("https://domain.auth0.com")
.buildAuthorizeURL(withRedirectURL: RedirectURL, defaults: newDefaults),
"domain": Domain,
"query": defaultQuery(withParameters: ["audience": "https://domain.auth0.com"]),
]
}

itBehavesLike(ValidAuthorizeURLExample) {
return [
"url": newWebAuth()
.audience("https://domain.auth0.com")
.buildAuthorizeURL(withRedirectURL: RedirectURL, defaults: defaults),
"domain": Domain,
"query": defaultQuery(withParameters: ["audience": "https://domain.auth0.com"]),
]
}
}

describe("redirect uri") {
Expand Down

0 comments on commit 7b83b28

Please sign in to comment.