Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow to customize URL for the OAuth2 authorization page #811

Merged
merged 1 commit into from
Jan 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Sources/BoxSDK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ public extension BoxSDK {
/// - Parameters:
/// - apiBaseURL: Base URL for majority of the requests.
/// - uploadApiBaseURL: Base URL for upload requests. If not specified, default URL is used.
/// - oauth2AuthorizeURL: URL for the OAuth2 authorization page, where users are redirected to enter their credentials
/// - maxRetryAttempts: Maximum number of request retries in case of error result. If not specified, default value 5 is used.
/// - tokenRefreshThreshold: Specifies how many seconds before token expires it shuld be refreshed.
/// If not specified, default value 60 seconds is used.
Expand All @@ -435,6 +436,7 @@ public extension BoxSDK {
func updateConfiguration(
apiBaseURL: URL? = nil,
uploadApiBaseURL: URL? = nil,
oauth2AuthorizeURL: URL? = nil,
maxRetryAttempts: Int? = nil,
tokenRefreshThreshold: TimeInterval? = nil,
consoleLogDestination: ConsoleLogDestination? = nil,
Expand All @@ -446,6 +448,7 @@ public extension BoxSDK {
clientSecret: configuration.clientSecret,
apiBaseURL: apiBaseURL,
uploadApiBaseURL: uploadApiBaseURL,
oauth2AuthorizeURL: oauth2AuthorizeURL,
maxRetryAttempts: maxRetryAttempts,
tokenRefreshThreshold: tokenRefreshThreshold,
consoleLogDestination: consoleLogDestination,
Expand Down
1 change: 1 addition & 0 deletions Sources/Core/BoxSDKConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public struct BoxSDKConfiguration {
/// - clientSecret: The client secret of the application requesting authentication.
/// - apiBaseURL: Base URL for majority of the requests.
/// - uploadApiBaseURL: Base URL for upload requests
/// - oauth2AuthorizeURL: URL for the OAuth2 authorization page, where users are redirected to enter their credentials
/// - maxRetryAttempts: Base URL for file upload requests.
/// - tokenRefreshThreshold: Specifies how long before token expiration date it should be refreshed.
/// - retryBaseInterval: The base factor used in calculating exponential backoff delay for retries
Expand Down
15 changes: 11 additions & 4 deletions Tests/BoxSDKSpecs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,20 @@ class BoxSDKSpecs: QuickSpec {

expect(sdk.configuration.apiBaseURL).to(equal(BoxSDK.defaultConfiguration.apiBaseURL))
expect(sdk.configuration.uploadApiBaseURL).to(equal(BoxSDK.defaultConfiguration.uploadApiBaseURL))
expect(sdk.configuration.oauth2AuthorizeURL).to(equal(BoxSDK.defaultConfiguration.oauth2AuthorizeURL))

let apiBaseURL = "https://validapibaseurl.com"
let uploadApiBaseURL = "https://validuploadapibaseurl.com"
let oauth2AuthorizeURL = "https://validurl.com/oauth2/authorize"

expect { try sdk.updateConfiguration(
apiBaseURL: URL(string: "https://validurl.com"),
uploadApiBaseURL: URL(string: "https://validurl.com")
apiBaseURL: URL(string: apiBaseURL),
uploadApiBaseURL: URL(string: uploadApiBaseURL),
oauth2AuthorizeURL: URL(string: oauth2AuthorizeURL)
) }.toNot(throwError())
expect(sdk.configuration.apiBaseURL).toNot(equal(BoxSDK.defaultConfiguration.apiBaseURL))
expect(sdk.configuration.uploadApiBaseURL).toNot(equal(BoxSDK.defaultConfiguration.uploadApiBaseURL))
expect(sdk.configuration.apiBaseURL).to(equal(URL(string: apiBaseURL)))
expect(sdk.configuration.uploadApiBaseURL).to(equal(URL(string: uploadApiBaseURL)))
expect(sdk.configuration.oauth2AuthorizeURL).to(equal(URL(string: oauth2AuthorizeURL)))
}
}

Expand Down