2017-03-07 5 views
2

현재 Outlook 메일 서비스를 사용하여 연락처/약속 및 메일을 얻으려고합니다. 그러나 나는 문제를 발견했습니다.Outlook OAuth2가 응용 프로그램으로 리디렉션 할 수 없습니다.

저는 여러 서비스를 통합하고 있기 때문에 라이브러리로 OAuth2Swift을 사용하여 모든 OAuth 호출을 작성합니다. enter image description here

README 그럼 내가 https://apps.dev.microsoft.com
에 전망에 대한 응용 프로그램을 만들어 내 키를 생성하고이

struct Consumer { 
    let consumerKey: String 
    let consumerSecret: String 
    let authorizeURL: String 
    let accessTokenURL: String 
    let responseType: String? 
    let requestTokenURL: String? 
} 

let Outlook = Consumer(
    consumerKey: "", 
    consumerSecret: "", 
    authorizeURL: "https://login.microsoftonline.com/common/oauth2/v2.0/authorize", 
    accessTokenURL: "https://login.microsoftonline.com/common/oauth2/v2.0/token", 
    responseType: "code", 
    requestTokenURL: nil) 

처럼 보이는 Constants 파일을 만든 자신의 설명처럼

은 내가 URL scheme를 생성 비밀로 만들고 내 응용 프로그램 안에 그들을 채 웁니다.

내 앱에 mobile application 플랫폼을 추가했습니다. 리디렉션

URI urn:ietf:wg:oauth:2.0:oob를 사용하라고 알려줍니다 그래서 내 코드는 내가 먼저 화면 내 메일/암호를 입력 할 수 코드를 실행이

@IBAction func btn_Outlook(_ sender: Any) { 
     let oauthOU = OAuth2Swift(
      consumerKey: Outlook.consumerKey, 
      consumerSecret: Outlook.consumerSecret, 
      authorizeUrl: Outlook.authorizeURL, 
      accessTokenUrl: Outlook.accessTokenURL, 
      responseType: Outlook.responseType!) 

     oauthOU.authorizeURLHandler = SafariURLHandler(viewController: self, oauthSwift: oauthOU) 
     oauthOU.authorize(
      withCallbackURL: "urn:ietf:wg:oauth:2.0:oob", 
      scope: "https://outlook.office.com/Mail.ReadWrite https://outlook.office.com/Mail.Send https://outlook.office.com/Calendars.ReadWrite https://outlook.office.com/Contacts.ReadWrite https://outlook.office.com/Tasks.ReadWrite", 
      state: state, 
      success: { credential, response, parameters in 
       print("logged in with \(credential), with response \(response) and parameters \(parameters)")}, 
      failure: { error in 
       print("error occured \(error.localizedDescription)") 
      } 
      ) 
     } 

같은 외모 권한을 부여합니다. 내 메일을 입력하면 비밀번호를 입력 할 수있는 다른 페이지/포털로 리디렉션됩니다. 암호를 입력하면 사용 권한 화면이 나에게 표시됩니다.

enter image description here

는 최대한 빨리 yes 충돌로 나에게 말하는 오류 줄 것이다 "주소가 유효하지 않기 때문에 사파리 페이지를 열 수 없습니다." 나는 이것이 실제로 redirect URI과 관련이 있다고 확신하지만, 이것을 실제로 고치는 방법을 모르겠습니다.

나는 누군가가 나를 도와 줄 수 있기를 바라고있다.

답변

0

나는 당신이 당신의 URL 방식 설정에서 식별자 urn:ietf:wg:oauth:2.0:oob를 지정하는 것을 잊었다 생각 (첫 번째 이미지를 참조하십시오 더 식별자 세트 없음)

+0

나는 그것을 추가했지만 전망으로 로그인 할 때 동일한 메시지가 – NoSixties

0

난 당신이 OAuthSwift 라이브러리에서 AppDelegate에에 redirect URI을 처리하는 것을 잊었다 생각이! 아래와 같이 AppDelegate에서 콜백을 처리해야합니다.

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool { 
    if (url.host == "oauth-callback") { 
    OAuthSwift.handle(url: url) 
    } 
    return true 
} 
+0

가 추가 깜빡 표시되지만 내 위임에 그 방법이 어떤 차이를하지 않았고 심지어라는되지 않습니다 . 트위터로 할 때 호출됩니다. – NoSixties

+0

안녕하세요,이 문제를 해결할 수 있었습니까? Xamarin-Mac-app에서 OneDrive로 인증하려고하는 것과 똑같은 문제가 있습니다. – Tom

+0

이미 여기에 언급되어 있습니다. - https://github.com/OAuthSwift/OAuthSwift – KiranJasvanee