美文网首页
2023-01-12 pub google验证

2023-01-12 pub google验证

作者: 我是小胡胡123 | 来源:发表于2023-01-27 17:24 被阅读0次

pub
https://github.com/dart-lang/pub

1、

flutter3.0
dart pub publish --server=自定义服务器
不需要google验证。

源码如下:

  Future<void> _publish(List<int> packageBytes) async {
    try {
      final officialPubServers = {
        'https://pub.dev',
        // [validateAndNormalizeHostedUrl] normalizes https://pub.dartlang.org
        // to https://pub.dev, so we don't need to do allow that here.

        // Pub uses oauth2 credentials only for authenticating official pub
        // servers for security purposes (to not expose pub.dev access token to
        // 3rd party servers).
        // For testing publish command we're using mock servers hosted on
        // localhost address which is not a known pub server address. So we
        // explicitly have to define mock servers as official server to test
        // publish command with oauth2 credentials.
        if (runningFromTest &&
            Platform.environment.containsKey('_PUB_TEST_DEFAULT_HOSTED_URL'))
          Platform.environment['_PUB_TEST_DEFAULT_HOSTED_URL'],
      };

      // Using OAuth2 authentication client for the official pub servers
      final isOfficialServer = officialPubServers.contains(host.toString());
      if (isOfficialServer && !cache.tokenStore.hasCredential(host)) {
        // Using OAuth2 authentication client for the official pub servers, when
        // we don't have an explicit token from [TokenStore] to use instead.
        //
        // This allows us to use `dart pub token add` to inject a token for use
        // with the official servers.
        await oauth2.withClient(cache, (client) {
          return _publishUsingClient(packageBytes, client);
        });
      } else {
        // For third party servers using bearer authentication client
        await withAuthenticatedClient(cache, host, (client) {
          return _publishUsingClient(packageBytes, client);
        });
      }
    } on PubHttpResponseException catch (error) {
      var url = error.response.request!.url;
      if (Uri.parse(url.origin) == Uri.parse(host.origin)) {
        handleJsonError(error.response);
      } else {
        rethrow;
      }
    }
  }

2 、

flutter2.5.3
pub
https://github.com/dart-lang/pub/releases/tag/SDK-2.14.0-334.0.dev

看到还是需要google验证的。 即使是publish到本地的pub server。
dart publish --server=http://localhost:8080

/Volumes/xx/myshared/opt/fvm/current/bin/cache/dart-sdk/bin/dart --enable-asserts --pause_isolates_on_start --enable-vm-service:53895 /Users/xxx/Downloads/pub-SDK-2.14.0-334.0.dev/bin/pub.dart publish --server=http://localhost:8080
Observatory listening on http://127.0.0.1:53895/l84thWyVIXE=/


Package validation found the following potential issue:
* ./CHANGELOG.md doesn't mention current version (0.13.26).
  Consider updating it with notes on this version prior to publication.

Publishing is forever; packages cannot be unpublished.
Policy details are available at https://pub.dev/policy


Package has 1 warning.. Do you want to publish httptest 0.13.26 (y/N)? y
Pub needs your authorization to upload packages on your behalf.
In a web browser, go to https://accounts.google.com/o/oauth2/auth?access_type=offline&approval_prompt=force&response_type=code&client_id=818368855108-8grd2eg9tj9f38os6f1urbcvsq399u8n.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Flocalhost%3A53964&code_challenge=e3kk_6M4AyIaU1-Bk7vpEsNs3GV46g4RtXvOfATMAyo&code_challenge_method=S256&scope=openid+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email
Then click "Allow access".

Waiting for your authorization...

源码如下:


  Future<void> _publish(List<int> packageBytes) async {
    Uri cloudStorageUrl;
    try {
      await oauth2.withClient(cache, (client) {
        return log.progress('Uploading', () async {
          var newUri = server.resolve('api/packages/versions/new');
          var response = await client.get(newUri, headers: pubApiHeaders);
          var parameters = parseJsonResponse(response);

          var url = _expectField(parameters, 'url', response);
          if (url is! String) invalidServerResponse(response);
          cloudStorageUrl = Uri.parse(url);
          // TODO(nweiz): Cloud Storage can provide an XML-formatted error. We
          // should report that error and exit.
          var request = http.MultipartRequest('POST', cloudStorageUrl);

          var fields = _expectField(parameters, 'fields', response);
          if (fields is! Map) invalidServerResponse(response);
          fields.forEach((key, value) {
            if (value is! String) invalidServerResponse(response);
            request.fields[key] = value;
          });

          request.followRedirects = false;
          request.files.add(http.MultipartFile.fromBytes('file', packageBytes,
              filename: 'package.tar.gz'));
          var postResponse =
              await http.Response.fromStream(await client.send(request));

          var location = postResponse.headers['location'];
          if (location == null) throw PubHttpException(postResponse);
          handleJsonSuccess(
              await client.get(Uri.parse(location), headers: pubApiHeaders));
        });
      });
    } on PubHttpException catch (error) {
      var url = error.response.request.url;
      if (url == cloudStorageUrl) {
        // TODO(nweiz): the response may have XML-formatted information about
        // the error. Try to parse that out once we have an easily-accessible
        // XML parser.
        fail(log.red('Failed to upload the package.'));
      } else if (Uri.parse(url.origin) == Uri.parse(server.origin)) {
        handleJsonError(error.response);
      } else {
        rethrow;
      }
    }
  }

相关文章

网友评论

      本文标题:2023-01-12 pub google验证

      本文链接:https://www.haomeiwen.com/subject/jbzbcdtx.html