Skip to content

Commit

Permalink
feat(auth): Removed dependency on oauth2 token for refreshToken and m…
Browse files Browse the repository at this point in the history
…ove to initiateAuth for hostedUI (#3497)
  • Loading branch information
harsh62 authored Feb 8, 2024
1 parent 9862d82 commit 4ab4c99
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 527 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,19 @@ extension RefreshSessionState {
case .notStarted:

if case .refreshCognitoUserPool(let signedInData) = event.isRefreshSessionEvent {
if case .hostedUI = signedInData.signInMethod {
let action = RefreshHostedUITokens(existingSignedIndata: signedInData)
return .init(newState: .refreshingUserPoolToken(signedInData),
actions: [action])
} else {
let action = RefreshUserPoolTokens(existingSignedIndata: signedInData)
return .init(newState: .refreshingUserPoolToken(signedInData),
actions: [action])
}
let action = RefreshUserPoolTokens(existingSignedIndata: signedInData)
return .init(newState: .refreshingUserPoolToken(signedInData),
actions: [action])
}

if case .refreshCognitoUserPoolWithIdentityId(
let signedInData,
let identityID) = event.isRefreshSessionEvent {

if case .hostedUI = signedInData.signInMethod {
let action = RefreshHostedUITokens(existingSignedIndata: signedInData)
return .init(
newState: .refreshingUserPoolTokenWithIdentity(signedInData,
identityID),
actions: [action])
} else {
let action = RefreshUserPoolTokens(existingSignedIndata: signedInData)
return .init(newState:
.refreshingUserPoolTokenWithIdentity(signedInData, identityID),
actions: [action])
}
let action = RefreshUserPoolTokens(existingSignedIndata: signedInData)
return .init(newState:
.refreshingUserPoolTokenWithIdentity(signedInData, identityID),
actions: [action])

}
if case .refreshUnAuthAWSCredentials(let identityID) = event.isRefreshSessionEvent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,36 +120,6 @@ struct HostedUIRequestHelper {
return urlRequest
}

static func createRefreshTokenRequest(
refreshToken: String,
configuration: HostedUIConfigurationData) throws -> URLRequest {

var components = URLComponents()
components.scheme = "https"
components.path = "/oauth2/token"
components.host = configuration.oauth.domain

guard let url = components.url else {
throw HostedUIError.tokenURI
}

var queryComponents = URLComponents()
queryComponents.queryItems = [
.init(name: "grant_type", value: "refresh_token"),
.init(name: "refresh_token", value: refreshToken),
.init(name: "client_id", value: configuration.clientId)]

guard let body = queryComponents.query else {
throw HostedUIError.tokenURI
}

var urlRequest = URLRequest(url: url)
urlRequest.httpMethod = "POST"
urlRequest.httpBody = Data(body.utf8)
urlRequest.addHeaders(using: configuration)
return urlRequest
}

static func urlSafeBase64(_ content: String) -> String {
return content.replacingOccurrences(of: "/", with: "_")
.replacingOccurrences(of: "+", with: "-")
Expand Down
Loading

0 comments on commit 4ab4c99

Please sign in to comment.