首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >LocalServer与颤振应用的连接

LocalServer与颤振应用的连接
EN

Stack Overflow用户
提问于 2019-11-27 12:27:03
回答 1查看 73关注 0票数 0

我有一个问题,有关颤振应用程序开发。问题是,“是否有可能在没有防火墙的情况下实现OAuth2?”

基本上,我希望将我的Android应用程序与自己的本地服务器链接起来,以验证用户的身份。每个人都先在那里注册,然后再向火场申请。如果有任何解决办法,请与我分享。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-11-28 04:01:51

您可以使用oauth2客户端包https://pub.dev/packages/oauth2

Github https://github.com/dart-lang/oauth2

客户端凭据授予代码段

代码语言:javascript
复制
// This URL is an endpoint that's provided by the authorization server. It's
// usually included in the server's documentation of its OAuth2 API.
final authorizationEndpoint =
    Uri.parse("http://example.com/oauth2/authorization");

// The OAuth2 specification expects a client's identifier and secret
// to be sent when using the client credentials grant.
//
// Because the client credentials grant is not inherently associated with a user,
// it is up to the server in question whether the returned token allows limited
// API access.
//
// Either way, you must provide both a client identifier and a client secret:
final identifier = "my client identifier";
final secret = "my client secret";

// Calling the top-level `clientCredentialsGrant` function will return a
// [Client] instead.
var client = await oauth2.clientCredentialsGrant(
    authorizationEndpoint, identifier, secret);

// With an authenticated client, you can make requests, and the `Bearer` token
// returned by the server during the client credentials grant will be attached
// to any request you make.
var response = await client.read("https://example.com/api/some_resource.json");

// You can save the client's credentials, which consists of an access token, and
// potentially a refresh token and expiry date, to a file. This way, subsequent runs
// do not need to reauthenticate, and you can avoid saving the client identifier and
// secret.
await credentialsFile.writeAsString(client.credentials.toJson());
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59070230

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档