Skip to content

Commit

Permalink
Added additionalParameters to TIMConfig / OIDAuthorizationResponse (#20)
Browse files Browse the repository at this point in the history
* Added additionalParameters to TIMConfig / OIDAuthorizationResponse

* additionalParameters, handle default values

* Fixed bug (fejl-40)
  • Loading branch information
tfctrifork authored Jun 2, 2022
1 parent 887eee9 commit 0851e52
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
8 changes: 4 additions & 4 deletions Sources/TIM/AppAuth/AppAuthController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public final class AppAuthController: OpenIDConnectController {
scopes: credentials.scopes,
redirectURL: credentials.redirectUri,
responseType: OIDResponseTypeCode,
additionalParameters: [:]
additionalParameters: credentials.additionalParameters
),
parameters: [:])
}
Expand Down Expand Up @@ -142,7 +142,7 @@ public final class AppAuthController: OpenIDConnectController {
scopes: self.credentials.scopes,
refreshToken: refreshToken.token,
codeVerifier: nil,
additionalParameters: nil
additionalParameters: self.credentials.additionalParameters
)
OIDAuthorizationService.perform(request) { [weak self] (token: OIDTokenResponse?, error: Error?) in
let result: Result<JWT, TIMAuthError>
Expand Down Expand Up @@ -254,7 +254,7 @@ public final class AppAuthController: OpenIDConnectController {
codeVerifier: nil,
codeChallenge: nil,
codeChallengeMethod: nil,
additionalParameters: [:]
additionalParameters: self.credentials.additionalParameters
)
} else {
return OIDAuthorizationRequest(
Expand All @@ -263,7 +263,7 @@ public final class AppAuthController: OpenIDConnectController {
scopes: self.credentials.scopes,
redirectURL: self.credentials.redirectUri,
responseType: OIDResponseTypeCode,
additionalParameters: [:]
additionalParameters: self.credentials.additionalParameters
)
}
}
Expand Down
6 changes: 4 additions & 2 deletions Sources/TIM/Models/TIMConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ public struct TIMConfiguration {
/// - scopes: Scopes, e.g. `["scope"]`
/// - encryptionMethod: Encryption method, e.g. `.aesGcm`
/// - keyServiceVersion: Optional key service version, defaults to `.v1`
public init(timBaseUrl: URL, realm: String, clientId: String, redirectUri: URL, scopes: [String], encryptionMethod: TIMESEncryptionMethod, keyServiceVersion: TIMKeyServiceVersion = .v1) {
/// - additionalParameters: Optional additional parameters, for e.g. app-switch `[:]`
public init(timBaseUrl: URL, realm: String, clientId: String, redirectUri: URL, scopes: [String], encryptionMethod: TIMESEncryptionMethod, keyServiceVersion: TIMKeyServiceVersion = .v1, additionalParameters: [String: String] = [:]) {

let fullTimUrl = timBaseUrl.appendingPathComponent("/auth/realms/\(realm)")
self.oidcConfiguration = TIMOpenIDConfiguration(
issuer: fullTimUrl,
clientId: clientId,
redirectUri: redirectUri,
scopes: scopes
scopes: scopes,
additionalParameters: additionalParameters
)
self.keyServiceConfiguration = TIMKeyServiceConfiguration(realmBaseUrl: fullTimUrl.absoluteString, version: keyServiceVersion)
self.encryptionMethod = encryptionMethod
Expand Down
6 changes: 5 additions & 1 deletion Sources/TIM/Models/TIMOpenIDConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@ public struct TIMOpenIDConfiguration {

/// Scopes
public let scopes: [String]

/// Scopes
public let additionalParameters: [String: String]

/// Constructor
public init(issuer: URL, clientId: String, redirectUri: URL, scopes: [String]) {
public init(issuer: URL, clientId: String, redirectUri: URL, scopes: [String], additionalParameters: [String: String] = [:]) {
self.issuer = issuer
self.clientId = clientId
self.redirectUri = redirectUri
self.scopes = scopes
self.additionalParameters = additionalParameters
}
}

0 comments on commit 0851e52

Please sign in to comment.