|
| 1 | +note |
| 2 | + description: "Summary description for {OAUTH_20_GOOGLE_API}." |
| 3 | + date: "$Date: 2020-08-04 12:05:41 -0300 (Tue, 04 Aug 2020) $" |
| 4 | + revision: "$Revision: 104570 $" |
| 5 | + EIS: "name=OAuth2 google apis", "src=https://developers.google.com/accounts/docs/OAuth2", "protocol=uri" |
| 6 | + |
| 7 | +class |
| 8 | + OAUTH_20_GOOGLE_API |
| 9 | + |
| 10 | +inherit |
| 11 | + |
| 12 | + OAUTH_20_API |
| 13 | + redefine |
| 14 | + access_token_extractor, |
| 15 | + access_token_verb |
| 16 | + end |
| 17 | + |
| 18 | +feature -- Access |
| 19 | + |
| 20 | + access_token_extractor: ACCESS_TOKEN_EXTRACTOR |
| 21 | + do |
| 22 | + create {JSON_TOKEN_EXTRACTOR} Result |
| 23 | + end |
| 24 | + |
| 25 | + access_token_verb: STRING_8 |
| 26 | + -- <Precursor> |
| 27 | + do |
| 28 | + Result := "POST" |
| 29 | + end |
| 30 | + |
| 31 | + access_token_endpoint: STRING_8 |
| 32 | + -- Url that receives the access token request |
| 33 | + do |
| 34 | + create {STRING_8} Result.make_from_string ("https://oauth2.googleapis.com/token") |
| 35 | + end |
| 36 | + |
| 37 | + authorization_url (config: OAUTH_CONFIG): detachable STRING_8 |
| 38 | + -- Url where you should redirect your users to authneticate |
| 39 | + do |
| 40 | + if attached config.scope as l_scope then |
| 41 | + create Result.make_from_string (TEMPLATE_AUTHORIZE_URL + SCOPED_AUTHORIZE_URL) |
| 42 | + Result.replace_substring_all ("$CLIENT_ID", config.api_key.as_string_8) |
| 43 | + if attached config.callback as l_callback then |
| 44 | + Result.replace_substring_all ("$REDIRECT_URI", (create {OAUTH_ENCODER}).encoded_string (l_callback.as_string_8)) |
| 45 | + end |
| 46 | + Result.replace_substring_all ("$SCOPE", (create {OAUTH_ENCODER}).encoded_string (l_scope.as_string_8)) |
| 47 | + else |
| 48 | + create Result.make_from_string (TEMPLATE_AUTHORIZE_URL) |
| 49 | + Result.replace_substring_all ("$CLIENT_ID", config.api_key.as_string_8) |
| 50 | + if attached config.callback as l_callback then |
| 51 | + Result.replace_substring_all ("$REDIRECT_URI", (create {OAUTH_ENCODER}).encoded_string (l_callback.as_string_8)) |
| 52 | + end |
| 53 | + end |
| 54 | + end |
| 55 | + |
| 56 | +feature -- Implementation |
| 57 | + |
| 58 | + Template_authorize_url: STRING_8 = "https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=$CLIENT_ID&redirect_uri=$REDIRECT_URI" |
| 59 | + |
| 60 | + Scoped_authorize_url: STRING = "&scope=$SCOPE" |
| 61 | + |
| 62 | +note |
| 63 | + copyright: "2013-2020, Javier Velilla, Jocelyn Fiat, Eiffel Software and others" |
| 64 | + license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" |
| 65 | + source: "[ |
| 66 | + Eiffel Software |
| 67 | + 5949 Hollister Ave., Goleta, CA 93117 USA |
| 68 | + Telephone 805-685-1006, Fax 805-685-6869 |
| 69 | + Website http://www.eiffel.com |
| 70 | + Customer support http://support.eiffel.com |
| 71 | + ]" |
| 72 | +end |
0 commit comments