~ci-train-bot/account-plugins/account-plugins-ubuntu-yakkety-1992

« back to all changes in this revision

Viewing changes to src/google.vala

  • Committer: Alberto Mardegan
  • Date: 2013-02-22 15:17:49 UTC
  • mto: This revision was merged to the branch mainline in revision 93.
  • Revision ID: alberto.mardegan@canonical.com-20130222151749-980i069e2qqxvb6i
Add a generic OAuth plugin

Remove most of the binaries

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 */
21
21
 
22
22
public class GooglePlugin : Ap.OAuthPlugin {
23
 
    private enum ParametersUser
24
 
    {
25
 
        ACCOUNT_PLUGIN,
26
 
        CLIENT_APPLICATIONS
27
 
    }
28
 
 
29
23
    public GooglePlugin (Ag.Account account) {
30
24
        Object (account: account);
31
25
    }
32
26
 
33
27
    construct
34
28
    {
35
 
        var oauth_params = get_parameters (ParametersUser.ACCOUNT_PLUGIN);
36
 
        set_oauth_parameters (oauth_params);
37
 
 
38
 
        oauth_params = get_parameters (ParametersUser.CLIENT_APPLICATIONS);
39
 
        set_account_oauth_parameters (oauth_params);
40
 
 
41
 
        set_mechanism (Ap.OAuthMechanism.WEB_SERVER);
42
 
 
43
 
        set_ignore_cookies (true);
44
 
    }
45
 
 
46
 
    private HashTable<string, GLib.Value?> get_parameters (ParametersUser user)
47
 
    {
48
29
        var oauth_params = new HashTable<string, GLib.Value?> (str_hash, null);
49
 
        oauth_params.insert ("ClientId", Config.GOOGLE_CLIENT_ID);
50
 
        oauth_params.insert ("ClientSecret", Config.GOOGLE_CLIENT_SECRET);
51
30
 
52
31
        /* Note the evil trick here: Google uses a couple of non-standard OAuth
53
32
         * parameters: "access_type" and "approval_prompt"; the signon OAuth
56
35
         *
57
36
         * We need to specify "access_type=offline" if we want Google to return
58
37
         * us a refresh token.
 
38
         * The "approval_prompt=force" string forces Google to ask for
 
39
         * authentication.
59
40
         */
60
 
        if (user == ParametersUser.ACCOUNT_PLUGIN)
61
 
        {
62
 
            /* The "approval_prompt=force" string forces Google to ask for
63
 
             * authentication. */
64
 
            oauth_params.insert ("ResponseType",
65
 
                                 "code&access_type=offline&approval_prompt=force");
66
 
        }
 
41
        oauth_params.insert ("ResponseType",
 
42
                             "code&access_type=offline&approval_prompt=force");
 
43
        set_oauth_parameters (oauth_params);
67
44
 
68
 
        return oauth_params;
 
45
        set_ignore_cookies (true);
69
46
    }
70
47
}
71
48