2016-12-31 63 views
0

我得到並嘗試了使用ADALiOS的大量樣本。正如你所知,ADALiOS不斷改變其實施。因爲我是一個快捷的初學者,所以我不知道如何從互聯網上做出樣本。ADALiOS AcquireToken()

我試了一個版本的adal 3.0(pre release)。您可以看到,下面的代碼是從下載的示例中複製的。無論其adal版本如何,每個示例都有authContext.acquireToken()或acquireTokenwithResource()方法中的編譯器錯誤,如'缺少參數標籤策略...'或'無法轉換ADAuthenticationResult ...'。任何人都可以幫助我? 錯誤消息爲completionBlock:....

感謝

authContext.acquireToken(withScopes: [Any](), additionalScopes: [Any](), clientId: clientId, redirectUri: redirectURL, identifier: id!, promptBehavior: prompt, extraQueryParameters: "", completionBlock: <#T##ADAuthenticationCallback!##ADAuthenticationCallback!##(ADAuthenticationResult?) -> Void#>){ 
     if result.status.value != AD_SUCCEEDED.value { 
      // Failed, return error description 
      completionHandler(false, result.error.description) 
     } 
     else { 
      // Succeeded, return the acess token 
      var token = result.accessToken 
      // Initialize the dependency resolver with the logged on context. 
      // The dependency resolver is passed to the Outlook library. 
      self.dependencyResolver = ADALDependencyResolver(context: authContext, resourceId: self.outlookResource, clientId: self.clientId, redirectUri: self.redirectURL) 
      completionHandler(true, token) 
     } 
    } 
+0

我可以有一個Swift ADAL的工作樣本?互聯網上沒有ADAL快速樣本。 – Aussie

回答

1

我剛剛得到這個工作使用阿達爾3.0(預發佈)。在查看示例時,ADAL API看起來已經改變。我找不到acquireTokenwithResource(),所以我用:

acquireToken(withScopes:additionalScopes:clientid:客戶redirectUri:標識符:, promptBehavior :)

我想我最大的問題並不在這裏註冊的本機應用程序:https://apps.dev.microsoft.com

當我這樣做並使用apps.dev.microsoft中的clientId和redirectURI,並且還包含正確的作用域後,我就能夠驗證並獲取accessToken。

我acquireToken是這樣的:

func acquireAuthToken(completion: ((AuthenticationResult) -> Void)?) { 

     let identity = ADUserIdentifier(id: "Default email address", type: ADUserIdentifierType(rawValue:1)) 



     self.context.acquireToken(withScopes: ["User.Read"], additionalScopes: nil, clientId: AppData.sharedInstance?.clientId, redirectUri: URL(string: (AppData.sharedInstance?.redirectUriString)!), identifier: identity, promptBehavior: AD_PROMPT_AUTO) { 
      (result) in 

      if let handler = completion { 
       if result!.status == AD_SUCCEEDED { 
        self.accessToken = result!.token 

        handler(AuthenticationResult.Success) 
       } 
       else { 
        handler(AuthenticationResult.Failure(result!.error)) 
       } 
      } 
     } 
    } 

的上下文是ADAuthenticationContext(權威:ppData.sharedInstance .authority,.Authority,錯誤:&錯誤)

HTH

相關問題