Skip to content

Commit

Permalink
Merge pull request #67 from cweinberger/feature/support-custom-tenantIDs
Browse files Browse the repository at this point in the history
Microsoft: Support custom tenant IDs
  • Loading branch information
0xTim authored Aug 25, 2020
2 parents 5b318a4 + c2b1928 commit 773a169
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
/*.xcodeproj
build
DerivedData/
.swiftpm/
9 changes: 6 additions & 3 deletions Sources/Imperial/Services/Microsoft/MicrosoftRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ import Vapor
import Foundation

public class MicrosoftRouter: FederatedServiceRouter {
public static var tenantIDEnvKey: String = "MICROSOFT_TENANT_ID"

public let tokens: FederatedServiceTokens
public let callbackCompletion: (Request, String)throws -> (Future<ResponseEncodable>)
public var scope: [String] = []
public let callbackURL: String
public let accessTokenURL: String = "https://login.microsoftonline.com/common/oauth2/v2.0/token"

public var tenantID: String { Environment.get(MicrosoftRouter.tenantIDEnvKey) ?? "common" }
public var accessTokenURL: String { "https://login.microsoftonline.com/\(self.tenantID)/oauth2/v2.0/token" }

public required init(
callback: String,
completion: @escaping (Request, String) throws -> (Future<ResponseEncodable>)
Expand All @@ -18,7 +21,7 @@ public class MicrosoftRouter: FederatedServiceRouter {
}

public func authURL(_ request: Request) throws -> String {
return "https://login.microsoftonline.com/common/oauth2/v2.0/authorize?"
return "https://login.microsoftonline.com/\(self.tenantID)/oauth2/v2.0/authorize?"
+ "client_id=\(self.tokens.clientID)&"
+ "response_type=code&"
+ "redirect_uri=\(self.callbackURL)&"
Expand Down

0 comments on commit 773a169

Please sign in to comment.