且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么在尝试登录Box时会收到重定向URI不匹配?

更新时间:2023-12-03 11:04:52

是我们的文档中的错误。如果您在您的redirect_uri的开发人员控制台中输入 boxsdk-YOUR_CLIENT_ID:// boxsdkoauth2redirect ,将YOUR_CLIENT_ID替换为您的实际客户端ID,就应该可以使用。


When using the Box SDK for iOS to do OAuth, I am shown a webpage with this error:

Error: redirect_uri_mismatch

response_type=code redirect_uri=boxsdk-our4iypzazstfpx8j70e8tlc3eyn9c4l://boxsdkoauth2redirect state=ok client_id=our4iypzazstfpx8j70e8tlc3eyn9c4l

I used the code that they suggested:

[self
    presentViewController:[[BoxAuthorizationViewController alloc]
        initWithAuthorizationURL:[[BoxSDK sharedSDK].OAuth2Session authorizeURL]
        redirectURI:nil
    ]
    animated:YES
    completion:nil
];

My client ID and client secret are set prior to this. In my info.plist file, I have boxsdk-our4iypzazstfpx8j70e8tlc3eyn9c4l as a URL scheme. The only instruction I could not follow is:

Note: When setting up your service on Box, leave the OAuth2 reditrect URI blank. The SDK will provide a custom redirect URI when issuing OAuth2 calls; doing so requires that no redirect URI be set in your service settings.

When I attempt to leave the redirect URI blank and save the form in the developer console, I get the this error:

OAuth2 redirect URL must specify a valid URL and must not be http://

So I am forced to input something. I have inputted "https://mydomain.com" (with my real domain). I modified the iOS code to pass that URI into the BoxAuthorizationViewController, but I still get the same error webpage.

Sorry, this was a mistake in our documentation. It should work if you enter boxsdk-YOUR_CLIENT_ID://boxsdkoauth2redirect into the developer console for your redirect_uri, replacing YOUR_CLIENT_ID with your actual client ID.