| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /// A client library for authenticating with a remote service via OAuth2 on | 5 /// A client library for authenticating with a remote service via OAuth2 on |
| 6 /// behalf of a user, and making authorized HTTP requests with the user's OAuth2 | 6 /// behalf of a user, and making authorized HTTP requests with the user's OAuth2 |
| 7 /// credentials. | 7 /// credentials. |
| 8 /// | 8 /// |
| 9 /// OAuth2 allows a client (the program using this library) to access and | 9 /// OAuth2 allows a client (the program using this library) to access and |
| 10 /// manipulate a resource that's owned by a resource owner (the end user) and | 10 /// manipulate a resource that's owned by a resource owner (the end user) and |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 /// that the library is being used by a server-side application. | 21 /// that the library is being used by a server-side application. |
| 22 /// | 22 /// |
| 23 /// import 'dart:io' | 23 /// import 'dart:io' |
| 24 /// import 'dart:uri' | 24 /// import 'dart:uri' |
| 25 /// import 'package:oauth2/oauth2.dart' as oauth2; | 25 /// import 'package:oauth2/oauth2.dart' as oauth2; |
| 26 /// | 26 /// |
| 27 /// // These URLs are endpoints that are provided by the authorization | 27 /// // These URLs are endpoints that are provided by the authorization |
| 28 /// // server. They're usually included in the server's documentation of its | 28 /// // server. They're usually included in the server's documentation of its |
| 29 /// // OAuth2 API. | 29 /// // OAuth2 API. |
| 30 /// final authorizationEndpoint = | 30 /// final authorizationEndpoint = |
| 31 /// new Uri.fromString("http://example.com/oauth2/authorization"); | 31 /// Uri.parse("http://example.com/oauth2/authorization"); |
| 32 /// final tokenEndpoint = | 32 /// final tokenEndpoint = |
| 33 /// new Uri.fromString("http://example.com/oauth2/token"); | 33 /// Uri.parse("http://example.com/oauth2/token"); |
| 34 /// | 34 /// |
| 35 /// // The authorization server will issue each client a separate client | 35 /// // The authorization server will issue each client a separate client |
| 36 /// // identifier and secret, which allows the server to tell which client | 36 /// // identifier and secret, which allows the server to tell which client |
| 37 /// // is accessing it. Some servers may also have an anonymous | 37 /// // is accessing it. Some servers may also have an anonymous |
| 38 /// // identifier/secret pair that any client may use. | 38 /// // identifier/secret pair that any client may use. |
| 39 /// // | 39 /// // |
| 40 /// // Note that clients whose source code or binary executable is readily | 40 /// // Note that clients whose source code or binary executable is readily |
| 41 /// // available may not be able to make sure the client secret is kept a | 41 /// // available may not be able to make sure the client secret is kept a |
| 42 /// // secret. This is fine; OAuth2 servers generally won't rely on knowing | 42 /// // secret. This is fine; OAuth2 servers generally won't rely on knowing |
| 43 /// // with certainty that a client is who it claims to be. | 43 /// // with certainty that a client is who it claims to be. |
| 44 /// final identifier = "my client identifier"; | 44 /// final identifier = "my client identifier"; |
| 45 /// final secret = "my client secret"; | 45 /// final secret = "my client secret"; |
| 46 /// | 46 /// |
| 47 /// // This is a URL on your application's server. The authorization server | 47 /// // This is a URL on your application's server. The authorization server |
| 48 /// // will redirect the resource owner here once they've authorized the | 48 /// // will redirect the resource owner here once they've authorized the |
| 49 /// // client. The redirection will include the authorization code in the | 49 /// // client. The redirection will include the authorization code in the |
| 50 /// // query parameters. | 50 /// // query parameters. |
| 51 /// final redirectUrl = new Uri.fromString( | 51 /// final redirectUrl = Uri.parse( |
| 52 /// "http://my-site.com/oauth2-redirect"); | 52 /// "http://my-site.com/oauth2-redirect"); |
| 53 /// | 53 /// |
| 54 /// var credentialsFile = new File("~/.myapp/credentials.json"); | 54 /// var credentialsFile = new File("~/.myapp/credentials.json"); |
| 55 /// return credentialsFile.exists().then((exists) { | 55 /// return credentialsFile.exists().then((exists) { |
| 56 /// // If the OAuth2 credentials have already been saved from a previous | 56 /// // If the OAuth2 credentials have already been saved from a previous |
| 57 /// // run, we just want to reload them. | 57 /// // run, we just want to reload them. |
| 58 /// if (exists) { | 58 /// if (exists) { |
| 59 /// return credentialsFile.readAsText().then((json) { | 59 /// return credentialsFile.readAsText().then((json) { |
| 60 /// var credentials = new oauth2.Credentials.fromJson(json); | 60 /// var credentials = new oauth2.Credentials.fromJson(json); |
| 61 /// return new oauth2.Client(identifier, secret, credentials); | 61 /// return new oauth2.Client(identifier, secret, credentials); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 /// }).then((file) => file.close()).then((_) => result); | 100 /// }).then((file) => file.close()).then((_) => result); |
| 101 /// }); | 101 /// }); |
| 102 /// }).then(print); | 102 /// }).then(print); |
| 103 library oauth2; | 103 library oauth2; |
| 104 | 104 |
| 105 export 'src/authorization_code_grant.dart'; | 105 export 'src/authorization_code_grant.dart'; |
| 106 export 'src/client.dart'; | 106 export 'src/client.dart'; |
| 107 export 'src/credentials.dart'; | 107 export 'src/credentials.dart'; |
| 108 export 'src/authorization_exception.dart'; | 108 export 'src/authorization_exception.dart'; |
| 109 export 'src/expiration_exception.dart'; | 109 export 'src/expiration_exception.dart'; |
| OLD | NEW |