我的应用程序正在请求“具有脱机访问权限”的许可,为什么?

克雷根

我的应用程序正在请求“具有脱机访问权限”的许可,为什么?这是最奇怪的事情。我已经做了一些搜索,还没有真正找到任何有效的方法。我尝试将这些用于范围:

https://www.googleapis.com/auth/plus.profile.emails.read 
https://www.googleapis.com/auth/plus.login

但这似乎没有帮助。

以下是屏幕截图和一些我的代码来帮助您了解发生了什么:

在此处输入图片说明

我的一些代码:

    #import "ViewController.h"

NSString *callbakc =  @"http://localhost/";
NSString *client_id = @“CLIENT ID“;
NSString *scope = @"https://www.googleapis.com/auth/userinfo.email+https://www.googleapis.com/auth/userinfo.profile+https://www.google.com/reader/api/0/subscription";
NSString *secret = @“SECRET”;
NSString *visibleactions = @"http://schemas.google.com/AddActivity";

@interface ViewController () {
NSString *authAccessToken;
UIAlertController *alertController;
}

@property (strong, nonatomic) NSMutableData *receivedData;
@property (weak, nonatomic) IBOutlet UIWebView *webView;

@end

@implementation ViewController

#pragma mark - Lifecycle

- (void)viewDidLoad {
[super viewDidLoad];


NSString *url = [NSString stringWithFormat:@"https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=%@&redirect_uri=%@&scope=%@&data-requestvisibleactions=%@",client_id,callbakc,scope,visibleactions];

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:10];

[_webView loadRequest:request];
}



#pragma mark - WebView Delegate

- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {

[self performSelector:@selector(progressDelay:) withObject:nil afterDelay:0.0];
if ([[[request URL] host] isEqualToString:@"localhost"]) {

    // Extract oauth_verifier from URL query
    NSString* verifier = nil;
    NSArray* urlParams = [[[request URL] query] componentsSeparatedByString:@"&"];
    for (NSString* param in urlParams) {
        if (![param isEqualToString:@"error=access_denied"]) {
            NSArray* keyValue = [param componentsSeparatedByString:@"="];
            NSString* key = [keyValue objectAtIndex:0];
            if ([key isEqualToString:@"code"]) {
                verifier = [keyValue objectAtIndex:1];
//                    NSLog(@"verifier %@",verifier);
                break;
            }
        }
        else {
            [self.navigationController popViewControllerAnimated:NO];
        }
    }

    if (!verifier==0) {
        [self showAlertViewWithTitle:@"" message:@"Please wait" okAction:NO];

        NSString *data = [NSString stringWithFormat:@"code=%@&client_id=%@&client_secret=%@&redirect_uri=%@&grant_type=authorization_code", verifier,client_id,secret,callbakc];
        NSString *url = [NSString stringWithFormat:@"https://accounts.google.com/o/oauth2/token"];
        NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:url]];
        [request setHTTPMethod:@"POST"];
        [request setHTTPBody:[data dataUsingEncoding:NSUTF8StringEncoding]];

        [request setHTTPShouldHandleCookies:NO];

        NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
        NSLog(@"Connection: %@", theConnection);

        self.receivedData = [[NSMutableData alloc] init];
    }
    else {
        // cancel button click
        NSLog(@"not Verified!!");
    }

    return NO;
}
return YES;
}

- (void)webViewDidStartLoad:(UIWebView *)webView {
// show progress
}

- (void)webViewDidFinishLoad:(UIWebView *)webView {
[alertController dismissViewControllerAnimated:YES completion:nil];
}

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {

if (error.code==102) //Frame load interrupted
    return;

[alertController dismissViewControllerAnimated:YES completion:nil];
[self showAlertViewWithTitle:@"Error" message:[error localizedDescription] okAction:YES];
}

#pragma mark - NSURLConnection Delegate

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[self.receivedData appendData:data];
}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{
[self showAlertViewWithTitle:@"Error" message:[NSString stringWithFormat:@"%@", error] okAction:YES];
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {

NSString *response = [[NSString alloc] initWithData:self.receivedData encoding:NSUTF8StringEncoding];

NSData *data = [response dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *tokenData = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];

if ([tokenData objectForKey:@"access_token"]) {
    authAccessToken = [tokenData objectForKey:@"access_token"];
    [self getUserInfo:authAccessToken];
}
else {
    [alertController dismissViewControllerAnimated:YES completion:nil];
    NSLog(@"RESULT: %@", tokenData);
    [self showAlertViewWithTitle:[tokenData objectForKey:@"name"] message:[NSString stringWithFormat:@"%@", tokenData] okAction:YES];

    // Flush all cached data
    [[NSURLCache sharedURLCache] removeAllCachedResponses];
}

}

#pragma mark - Private Method Implementation

-(void)getUserInfo:(NSString *)token {
NSString *url = [NSString stringWithFormat:@"https://www.googleapis.com/oauth2/v1/userinfo?access_token=%@",token];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:url]];
[request setHTTPMethod:@"GET"];
[request setHTTPShouldHandleCookies:NO];

NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:request delegate:self];
NSLog(@"Connection: %@", theConnection);

self.receivedData = [[NSMutableData alloc] init];

}

-(void)progressDelay:(id)sender {
// Dismiss progress
}


@end

任何帮助将不胜感激!

谢谢

怀特罗

这来自https://stackoverflow.com/questions/32210920/why-is-my-app-asking-for-permission-to-have-offline-access?answertab=oldest#tab-top

这是正常现象,并且在用户已经授予权限时发生。

基本上,除非您真的不希望显示该令牌,否则无需担心,在这种情况下,您需要先取消对用户旧令牌的身份验证,然后再请求新令牌。

我不确定该怎么做,因为我之前没有做过,但是在您授权一个新令牌之前,您需要先取消对旧令牌的授权。

您需要修改-(void)getUserInfo:(NSString *)token方法。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

为什么我的应用程序说我正在请求“联系人”权限?

应用程序正在请求我未在清单中添加的权限

我的应用程序在请求权限之前崩溃

AADSTS65005:应用程序“ CLIENT_ID”正在请求无效或过期的权限。”

为什么我的应用程序未在清单中声明,但为什么仍具有READ_PHONE_STATE权限?

为什么我的Android应用程序(具有root特权)不能访问/ dev / input?

为什么没有任何权限且具有export = true的Content Provider可以访问任何应用程序?

如何隐藏“应用程序正在请求访问受保护的项目”弹出窗口

为什么我的iOS应用程序不要求用户访问相机的权限?

桌面应用程序具有多个Google访问权限

Windows为什么不在请求屏幕的同一屏幕上打开应用程序?

为什么“ Ubuntu应用”具有对我的Google帐户的完全访问权限?

为什么我没有写外部存储上的应用程序目录的权限?

iOS 9通知-为什么在我请求权限时我的应用程序名称丢失?

为什么我的应用程序要求未在Azure AD应用程序中配置的权限

为什么在Azure AD的“请求API权限”中禁用“应用程序权限”?

为什么脱机Web应用程序不起作用?

具有重写URL的脱机Web应用程序

为什么Firebase未经INTERNET许可即可在我的应用程序上运行

为什么我的Ionic应用程序要求获得相机许可?以及如何关闭它?

如何允许Travis-CI访问具有受限应用程序访问权限的GitHub组织?

在请求权限之前关闭 Android 应用程序?那怎么解决?

我正在尝试部署Laravel 4应用程序,但是工匠没有显示任何命令。为什么?

当我刚打开应用程序时,为什么Chrome有这么多正在运行的进程?

为用户提供对脱机HTML5 Web应用程序的访问权限

为什么我的应用程序中有很多图标?

该应用程序将从具有接收访问权限的应用程序列表中消失

尽管具有必要的权限,但新部署的云运行应用程序仍无法访问 (403)

具有公共访问权限的Web应用程序的Google OAuth 2.0刷新令牌