【问题标题】:Sales Force getting refresh token using ZKForce销售人员使用 ZKForce 获取刷新令牌
【发布时间】:2013-07-12 00:57:40
【问题描述】:

我正在使用 ZKForce 将 Sales Force 集成到我的应用中。直到现在我成功了,但现在我面临刷新令牌的问题。

当我从我的应用程序登录到销售人员时,我正在执行以下操作。

- (void)loginResult:(ZKLoginResult *)result error:(NSError *)error
{
    if (result && !error)
    {
        NSLog(@"session id is %@",result.sessionId);
        [SFAccountManager sharedInstance].coordinator.credentials.accessToken = result.sessionId;
        NSLog(@"Login Successful");
    }
    else if (error)
    {
        UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Connection failed" message:@"Failed connecting to server. Please try again" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
        [myAlertView show];

    }
}

这里我只是设置访问令牌,而不是设置刷新令牌。

我下载了示例案例备忘录应用程序,成功登录后显示如下。

- (void)loginOAuth:(FDCOAuthViewController *)oAuthViewController error:(NSError *)error
{
    if ([oAuthViewController accessToken] && !error)
    {
        NSLog(@"Logged in to Salesforce");
        [[FDCServerSwitchboard switchboard] setClientId:kSFOAuthConsumerKey];
        [[FDCServerSwitchboard switchboard] setApiUrlFromOAuthInstanceUrl:[oAuthViewController instanceUrl]];
        [[FDCServerSwitchboard switchboard] setSessionId:[oAuthViewController accessToken]];
        [[FDCServerSwitchboard switchboard] setOAuthRefreshToken:[oAuthViewController refreshToken]];
        NSLog(@"oauth token is %@",[oAuthViewController accessToken]);
        NSLog(@"oauth token is %@",[oAuthViewController refreshToken]);
        [self.splitViewController dismissModalViewControllerAnimated:YES];
        [self.oAuthViewController autorelease];

        // STEP 3 b - Save OAuth data after login
        [self saveOAuthData: oAuthViewController];

        [self didLogin];
    }
    else if (error)
    {
        [CaseMemoAppDelegate errorWithError:error];
    }
}

他们在这里设置刷新令牌。

那么我如何从我的代码中获取该刷新令牌。请帮我。谢谢

【问题讨论】:

    标签: ios salesforce access-token


    【解决方案1】:

    刷新令牌仅与 OAuth 流相关,与标准登录无关。如果您的第一件作品使用标准登录(直接提交用户名/密码),您将不会获得刷新令牌。如果您确实使用 OAuth,那么您的代码基本上可以显示您在首次登录服务器时获得的刷新令牌,并获取新的访问令牌(当前令牌过期时需要)。

    【讨论】:

    • 如何查看是否过期???每当我登录访问令牌时,我得到的都是相同的。但是,如果我让应用程序长时间闲置并尝试访问数据,则会引发错误。
    猜你喜欢
    • 2022-01-23
    • 1970-01-01
    • 2020-09-25
    • 2019-10-26
    • 2015-07-19
    • 1970-01-01
    • 2021-09-24
    • 2019-05-15
    • 2015-04-10
    相关资源
    最近更新 更多