-
Notifications
You must be signed in to change notification settings - Fork 252
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from sqrrrl/master
Base version of 3LO support.
- Loading branch information
Showing
24 changed files
with
1,636 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,31 @@ | ||
# This configuration was generated by `rubocop --auto-gen-config` | ||
# on 2015-05-18 09:38:28 -0700 using RuboCop version 0.31.0. | ||
# This configuration was generated by | ||
# `rubocop --auto-gen-config` | ||
# on 2015-10-14 13:50:41 -0700 using RuboCop version 0.34.2. | ||
# The point is for the user to remove these configuration records | ||
# one by one as the offenses are removed from the code base. | ||
# Note that changes in the inspected code, or installation of new | ||
# versions of RuboCop, may require this file to be generated again. | ||
|
||
# Offense count: 3 | ||
# Offense count: 4 | ||
Metrics/AbcSize: | ||
Max: 24 | ||
Max: 27 | ||
|
||
# Offense count: 10 | ||
# Offense count: 1 | ||
# Configuration parameters: CountComments. | ||
Metrics/ClassLength: | ||
Max: 109 | ||
|
||
# Offense count: 1 | ||
Metrics/CyclomaticComplexity: | ||
Max: 7 | ||
|
||
# Offense count: 16 | ||
# Configuration parameters: CountComments. | ||
Metrics/MethodLength: | ||
Max: 13 | ||
Max: 22 | ||
|
||
# Offense count: 2 | ||
# Configuration parameters: EnforcedStyle, SupportedStyles. | ||
Style/FormatString: | ||
Exclude: | ||
- 'lib/googleauth/user_authorizer.rb' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
# Copyright 2014, Google Inc. | ||
# All rights reserved. | ||
# | ||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions are | ||
# met: | ||
# | ||
# * Redistributions of source code must retain the above copyright | ||
# notice, this list of conditions and the following disclaimer. | ||
# * Redistributions in binary form must reproduce the above | ||
# copyright notice, this list of conditions and the following disclaimer | ||
# in the documentation and/or other materials provided with the | ||
# distribution. | ||
# * Neither the name of Google Inc. nor the names of its | ||
# contributors may be used to endorse or promote products derived from | ||
# this software without specific prior written permission. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
require 'multi_json' | ||
|
||
module Google | ||
module Auth | ||
# Representation of an application's identity for user authorization | ||
# flows. | ||
class ClientId | ||
INSTALLED_APP = 'installed' | ||
WEB_APP = 'web' | ||
CLIENT_ID = 'client_id' | ||
CLIENT_SECRET = 'client_secret' | ||
MISSING_TOP_LEVEL_ELEMENT_ERROR = | ||
"Expected top level property 'installed' or 'web' to be present." | ||
|
||
# Text identifier of the client ID | ||
# @return [String] | ||
attr_reader :id | ||
|
||
# Secret associated with the client ID | ||
# @return [String] | ||
attr_reader :secret | ||
|
||
class << self | ||
attr_accessor :default | ||
end | ||
|
||
# Initialize the Client ID | ||
# | ||
# @param [String] id | ||
# Text identifier of the client ID | ||
# @param [String] secret | ||
# Secret associated with the client ID | ||
# @note Direction instantion is discouraged to avoid embedding IDs | ||
# & secrets in source. See {#from_file} to load from | ||
# `client_secrets.json` files. | ||
def initialize(id, secret) | ||
fail 'Client id can not be nil' if id.nil? | ||
fail 'Client secret can not be nil' if secret.nil? | ||
@id = id | ||
@secret = secret | ||
end | ||
|
||
# Constructs a Client ID from a JSON file downloaed from the | ||
# Google Developers Console. | ||
# | ||
# @param [String, File] file | ||
# Path of file to read from | ||
# @return [Google::Auth::ClientID] | ||
def self.from_file(file) | ||
fail 'File can not be nil.' if file.nil? | ||
File.open(file.to_s) do |f| | ||
json = f.read | ||
config = MultiJson.load(json) | ||
from_hash(config) | ||
end | ||
end | ||
|
||
# Constructs a Client ID from a previously loaded JSON file. The hash | ||
# structure should | ||
# match the expected JSON format. | ||
# | ||
# @param [hash] config | ||
# Parsed contents of the JSON file | ||
# @return [Google::Auth::ClientID] | ||
def self.from_hash(config) | ||
fail 'Hash can not be nil.' if config.nil? | ||
raw_detail = config[INSTALLED_APP] || config[WEB_APP] | ||
fail MISSING_TOP_LEVEL_ELEMENT_ERROR if raw_detail.nil? | ||
ClientId.new(raw_detail[CLIENT_ID], raw_detail[CLIENT_SECRET]) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# Copyright 2015, Google Inc. | ||
# All rights reserved. | ||
# | ||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions are | ||
# met: | ||
# | ||
# * Redistributions of source code must retain the above copyright | ||
# notice, this list of conditions and the following disclaimer. | ||
# * Redistributions in binary form must reproduce the above | ||
# copyright notice, this list of conditions and the following disclaimer | ||
# in the documentation and/or other materials provided with the | ||
# distribution. | ||
# * Neither the name of Google Inc. nor the names of its | ||
# contributors may be used to endorse or promote products derived from | ||
# this software without specific prior written permission. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
require 'googleauth/signet' | ||
require 'googleauth/credentials_loader' | ||
require 'multi_json' | ||
|
||
module Google | ||
module Auth | ||
# Small utility for normalizing scopes into canonical form | ||
module ScopeUtil | ||
ALIASES = { | ||
'email' => 'https://www.googleapis.com/auth/userinfo.email', | ||
'profile' => 'https://www.googleapis.com/auth/userinfo.profile', | ||
'openid' => 'https://www.googleapis.com/auth/plus.me' | ||
} | ||
|
||
def self.normalize(scope) | ||
list = as_array(scope) | ||
list.map { |item| ALIASES[item] || item } | ||
end | ||
|
||
def self.as_array(scope) | ||
case scope | ||
when Array | ||
scope | ||
when String | ||
scope.split(' ') | ||
else | ||
fail 'Invalid scope value. Must be string or array' | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.