我有一个问题,有关颤振应用程序开发。问题是,“是否有可能在没有防火墙的情况下实现OAuth2?”
基本上,我希望将我的Android应用程序与自己的本地服务器链接起来,以验证用户的身份。每个人都先在那里注册,然后再向火场申请。如果有任何解决办法,请与我分享。
发布于 2019-11-28 04:01:51
您可以使用oauth2客户端包https://pub.dev/packages/oauth2
Github https://github.com/dart-lang/oauth2
客户端凭据授予代码段
// 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());https://stackoverflow.com/questions/59070230
复制相似问题