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

[Task] add a aad token for getting the acs token in joining a call #380

Merged
merged 4 commits into from
Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ import Foundation
import AzureCommunicationCommon

class AuthenticationHelper {
static func getCommunicationToken(tokenUrl: URL) -> TokenRefresher {
static func getCommunicationToken(tokenUrl: URL, aadToken: String? = nil) -> TokenRefresher {
return { completionHandler in
struct TokenResponse: Decodable {
let token: String
}
var urlRequest = URLRequest(url: tokenUrl, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10)
urlRequest.httpMethod = "GET"
if let aadToken = aadToken {
let value = "Bearer \(aadToken)"
kevinyulu marked this conversation as resolved.
Show resolved Hide resolved
urlRequest.setValue(value, forHTTPHeaderField: "Authorization")
}
URLSession.shared.dataTask(with: urlRequest) { (data, _, error) in
if let error = error {
print(error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import AzureCommunicationUICalling
import SwiftUI

enum EnvConfig: String {
case aadToken
case appCenterSecret
case acsToken
case acsTokenUrl
Expand All @@ -26,6 +27,7 @@ enum EnvConfig: String {
}

class EnvConfigSubject: ObservableObject {
@Published var aadToken: String = EnvConfig.aadToken.value()
@Published var appCenterSecret: String = EnvConfig.appCenterSecret.value()
@Published var acsToken: String = EnvConfig.acsToken.value()
@Published var expiredAcsToken: String = EnvConfig.expiredAcsToken.value()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,7 @@
<string>${groupCallId}</string>
<key>teamsMeetingLink</key>
<string>${teamsMeetingLink}</string>
<key>aadToken</key>
<string>${aadToken}</string>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ extension SwiftUIDemoView {
}
case .tokenUrl:
if let url = URL(string: envConfigSubject.acsTokenUrl) {
let tokenRefresher = AuthenticationHelper.getCommunicationToken(tokenUrl: url)
let tokenRefresher = AuthenticationHelper.getCommunicationToken(tokenUrl: url,
aadToken: envConfigSubject.aadToken)
let initialToken = await AuthenticationHelper.fetchInitialToken(with: tokenRefresher)
let communicationTokenRefreshOptions = CommunicationTokenRefreshOptions(initialToken: initialToken,
refreshProactively: true,
Expand Down