Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auth0 client Header information #123

Merged
merged 3 commits into from
May 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
source 'https://rubygems.org'

gem 'cocoapods', '0.36.0'
gem 'cocoapods', '~> 0.36'
gem 'cocoapods-packager'
gem 'cocoapods-deintegrate'
gem 'cocoapods-dependencies'
gem 'cocoapods-dependencies'
gem 'rake'
gem 'git'
6 changes: 5 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,15 @@ GEM
colored (1.2)
escape (0.0.4)
fuzzy_match (2.0.4)
git (1.2.9.1)
i18n (0.7.0)
json (1.8.2)
minitest (5.5.1)
molinillo (0.2.3)
nap (0.8.0)
netrc (0.7.8)
open4 (1.3.4)
rake (10.4.2)
thread_safe (0.3.5)
tzinfo (1.2.2)
thread_safe (~> 0.1)
Expand All @@ -58,7 +60,9 @@ PLATFORMS
ruby

DEPENDENCIES
cocoapods (= 0.36.0)
cocoapods (~> 0.36)
cocoapods-deintegrate
cocoapods-dependencies
cocoapods-packager
git
rake
5 changes: 4 additions & 1 deletion Lock.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
LOCK_VERSION = File.read('Pod/version')

Pod::Spec.new do |s|
s.name = "Lock"
s.version = "1.12.1"
s.version = "#{LOCK_VERSION}"
s.summary = "A library that uses Auth0 for Authentication with Native Look & Feel"
s.description = <<-DESC
[![Auth0](https://i.cloudup.com/1vaSVATKTL.png)](http://auth0.com)
Expand All @@ -23,6 +25,7 @@ Auth0 is a SaaS that helps you with Authentication and Authorization. You can us
s.default_subspecs = 'UI', 'Core'
s.prefix_header_contents = <<-EOS
#import "A0Logging.h"
#define A0CurrentLockVersion @"#{LOCK_VERSION}"
#define A0LocalizedString(key) NSLocalizedStringFromTable(key, @"Lock", nil)
EOS

Expand Down
2 changes: 1 addition & 1 deletion Lock/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ SPEC CHECKSUMS:
ISO8601DateFormatter: ab926648eebe497f4d167c0fd083992f959f1274
JWTDecode: bff190dc06ff9ee7a3a244c454dc8ef05962c994
libextobjc: a650fc1bf489a3d3a9bc2e621efa3e1006fc5471
Lock: ea007a23242b55f95433b848f9223e297165739d
Lock: 4337a4a3972333ec73bb06855ae54173cab8d437
Lock-Facebook: 02c315b7d15d6fed20c7a2ea8a5e5e27c072483a
Lock-GooglePlus: 38ea73da70d3dd3d210dfb7716b5aeed5aaabca6
Lock-Twitter: 61168e95f6614535167621794cbada2d6606d4c5
Expand Down
4 changes: 4 additions & 0 deletions Pod/Classes/Core/A0APIClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#import "A0UserAPIClient.h"
#import "A0APIv1Router.h"
#import "A0Lock.h"
#import "A0Stats.h"

#define kClientIdParamName @"client_id"
#define kUsernameParamName @"username"
Expand Down Expand Up @@ -73,6 +74,9 @@ - (instancetype)initWithAPIRouter:(id<A0APIRouter>)router {
_manager = [[AFHTTPSessionManager alloc] initWithBaseURL:[router endpointURL]];
_manager.requestSerializer = [AFJSONRequestSerializer serializer];
_manager.responseSerializer = [A0JSONResponseSerializer serializer];
if ([A0Stats shouldSendAuth0ClientHeader]) {
[_manager.requestSerializer setValue:[A0Stats stringForAuth0ClientHeader] forHTTPHeaderField:A0ClientInfoHeaderName];
}
}
return self;
}
Expand Down
34 changes: 34 additions & 0 deletions Pod/Classes/Core/Private/A0Stats.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// A0Stats.h
//
// Copyright (c) 2015 Auth0 (http://auth0.com)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

#import <Foundation/Foundation.h>

FOUNDATION_EXPORT NSString * const A0ClientInfoHeaderName;
FOUNDATION_EXPORT NSString * const A0ClientInfoQueryParamName;

@interface A0Stats : NSObject

+ (BOOL)shouldSendAuth0ClientHeader;

+ (NSString *)stringForAuth0ClientHeader;

@end
53 changes: 53 additions & 0 deletions Pod/Classes/Core/Private/A0Stats.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// A0Stats.m
//
// Copyright (c) 2015 Auth0 (http://auth0.com)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

#import "A0Stats.h"

NSString * const A0ClientInfoHeaderName = @"Auth0-Client";
NSString * const A0ClientInfoQueryParamName = @"auth0Client";

@implementation A0Stats

+ (BOOL)shouldSendAuth0ClientHeader {
NSDictionary *info = [[NSBundle mainBundle] infoDictionary];
NSNumber *optOut = info[@"Auth0SendSDKInfo"];
return optOut ?: @YES;
}

+ (NSString *)stringForAuth0ClientHeader {
static NSString *base64;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
NSDictionary *value = @{
@"name": @"Lock.iOS-OSX",
@"version": A0CurrentLockVersion,
};
NSData *data = [NSJSONSerialization dataWithJSONObject:value options:0 error:nil];
base64 = [data base64EncodedStringWithOptions:0];
base64 = [base64 stringByReplacingOccurrencesOfString:@"=" withString:@""];
base64 = [base64 stringByReplacingOccurrencesOfString:@"/" withString:@"_"];
base64 = [base64 stringByReplacingOccurrencesOfString:@"+" withString:@"-"];
});
return base64;
}

@end
4 changes: 4 additions & 0 deletions Pod/Classes/Provider/A0WebAuthenticator.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

#import <UIKit/UIKit.h>
#import "NSObject+A0APIClientProvider.h"
#import "A0Stats.h"

@interface A0WebAuthenticator ()

Expand Down Expand Up @@ -70,6 +71,9 @@ - (instancetype)initWithStrategy:(A0Strategy *)strategy
@"client_id": application.identifier,
@"redirect_uri": _authentication.callbackURL.absoluteString,
}];
if ([A0Stats shouldSendAuth0ClientHeader]) {
parameters[A0ClientInfoQueryParamName] = [A0Stats stringForAuth0ClientHeader];
}
_parameters = parameters;
_strategy = strategy;
_components = components;
Expand Down
4 changes: 4 additions & 0 deletions Pod/Classes/UI/A0WebViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#import <libextobjc/EXTScope.h>
#import "A0Lock.h"
#import "NSObject+A0APIClientProvider.h"
#import "A0Stats.h"

@interface A0WebViewController () <UIWebViewDelegate>
@property (weak, nonatomic) IBOutlet UIButton *cancelButton;
Expand Down Expand Up @@ -66,6 +67,9 @@ - (instancetype)initWithApplication:(A0Application *)application strategy:(A0Str
@"client_id": application.identifier,
@"redirect_uri": _authentication.callbackURL.absoluteString,
}];
if ([A0Stats shouldSendAuth0ClientHeader]) {
parameters[A0ClientInfoQueryParamName] = [A0Stats stringForAuth0ClientHeader];
}
[defaultParameters addValuesFromParameters:parameters];
NSDictionary *payload = [defaultParameters asAPIPayload];
components.query = payload.queryString;
Expand Down
1 change: 1 addition & 0 deletions Pod/version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.12.1
86 changes: 86 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/usr/bin/env rake
require 'cocoapods'
require 'git'

PROJECT_DIR = 'Lock'
VERSION_FILE_PATH = 'Pod/version'

class Semver
def initialize(args)
@major = args[:major].to_i
@minor = args[:minor].to_i
@patch = args[:patch].to_i
end

def to_s
"#{@major}.#{@minor}.#{@patch}"
end

def next(version=:patch)
args = {
major: @major,
minor: @minor,
patch: @patch
}
args[:major] = @major + 1 if version == :major
args[:minor] = @minor + 1 if version == :minor
args[:patch] = @patch + 1 if version == :patch
args[:minor] = 0 if version == :major
args[:patch] = 0 if version == :major or version == :minor
Semver.new args
end

def self.from_file(file_path)
version_string = File.read(file_path)
parts = version_string.split '.'
Semver.new major: parts[0], minor: parts[1], patch: parts[2]
end
end

def make_release(version)
version = Semver.from_file(VERSION_FILE_PATH).next(version)
puts "Bump version to #{version.to_s}"
File.open(VERSION_FILE_PATH, 'w') {|f| f.write(version.to_s) }
Rake::Task['pod:sync'].reenable
Rake::Task['pod:sync'].invoke
g = Git.init
g.add ['Lock/Podfile.lock', 'Pod/version']
g.commit "Release #{version.to_s}"
g.add_tag(version.to_s)
end

namespace :pod do
task :init do
installer = Pod::Command.parse(['install', "--project-directory=#{PROJECT_DIR}"])
installer.validate!
installer.run()
end

task :sync do
installer = Pod::Command.parse(['update', 'Lock', "--project-directory=#{PROJECT_DIR}"])
installer.validate!
installer.run()
end
end

namespace :release do

task :patch do
make_release :patch
end

task :minor do
make_release :minor
end

task :major do
make_release :major
end

task :push do
pusher = Pod::Command.parse(['trunk', 'push', '--use-libraries', '--allow-warnings'])
pusher.validate!
pusher.run()
end

end