OAuth consent screen error 'Google has not verified this app'

44 Views Asked by At

I want to fetch folders and files from google drive, If I'm using un-restricted scope the user logged-in and only those files and folders are fetched which I can upload from my app. If I'm using drive.DriveApi.ReadOnlyScope which is restricted and try to run my app it shows OAuth consent screen that "Google hasn't verified this app" But I use the app in 'testing' and add test users in OAuth consent screen:

Screenshot 1

If I clicked on 'Continue' then:

Screenshot 2

I'm adding the scope correctly:

I'm adding the scope correctly

Here's my code:

class GoogleDriveHandler {
  GoogleDriveHandler._internal();
  static final GoogleDriveHandler _googleDriveHandler =
      GoogleDriveHandler._internal();
  factory GoogleDriveHandler() => _googleDriveHandler;

  google_sign_in.GoogleSignInAccount? account;
  drive.FileList? fileList;
  String? pageToken;
  String? _googlDriveApiKey;

  setAPIKey({required String apiKey}) {
    _googlDriveApiKey = apiKey;
  }

  Future getFileFromGoogleDrive({required BuildContext context}) async {
    if (_googlDriveApiKey != null) {
      await _signinUser();
      if (account != null) {
        return await openGoogleDriveScreen(context);
      } else {
        log("Google Signin was declined by the user!");
      }
    } else {
      log('GOOGLEDRIVEAPIKEY has not yet been set. Please follow the documentation and call GoogleDriveHandler().setApiKey(YourAPIKey); to set your own API key');
    }
  }

  Future _signinUser() async {
    final googleSignIn = GoogleSignIn.standard(
      scopes: [
        drive.DriveApi.driveReadonlyScope,
      ],
    );
    account = await googleSignIn.signIn();
    return;
  }

  openGoogleDriveScreen(BuildContext context) async {
    final authHeader = await account!.authHeaders;
    log(account!.displayName.toString());
    final authenticateClient = _GoogleAuthClient(authHeader);
    final driveApi = drive.DriveApi(authenticateClient);

    drive.FileList? fileList = await driveApi.files.list(
      spaces: "drive",
    );
    print(fileList.files?.toList());
    return Navigator.of(context).push(
      MaterialPageRoute(
        builder: (context) => GoogleDriveScreen(
          fileList: fileList,
          googleDriveApiKey: _googlDriveApiKey.toString(),
          authenticateClient: authenticateClient,
          userName: account!.displayName!.substring(
            0,
            account!.displayName!.indexOf(" "),
          ),
        ),
      ),
    );
  }
}

class _GoogleAuthClient extends http.BaseClient {
  final Map<String, String> _headers;

  final http.Client _client = http.Client();

  _GoogleAuthClient(this._headers);

  @override
  Future<http.StreamedResponse> send(http.BaseRequest request) {
    return _client.send(request..headers.addAll(_headers));
  }
}```


How can I sign-in and fetch all the folders and files in testing mode, without verify my app?
0

There are 0 best solutions below