| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 = Uri.parse( | 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.readAsString().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); |
| 62 /// }); | 62 /// }); |
| 63 /// } | 63 /// } |
| 64 /// | 64 /// |
| 65 /// // If we don't have OAuth2 credentials yet, we need to get the | 65 /// // If we don't have OAuth2 credentials yet, we need to get the |
| 66 /// // resource owner to authorize us. We're assuming here that we're a | 66 /// // resource owner to authorize us. We're assuming here that we're a |
| 67 /// // command-line application. | 67 /// // command-line application. |
| 68 /// var grant = new oauth2.AuthorizationCodeGrant( | 68 /// var grant = new oauth2.AuthorizationCodeGrant( |
| 69 /// identifier, secret, authorizationEndpoint, tokenEndpoint); | 69 /// identifier, secret, authorizationEndpoint, tokenEndpoint); |
| (...skipping 30 matching lines...) Expand all 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 |