Skip to content

Commit

Permalink
[various] added formatting workflow to fire on push (#545)
Browse files Browse the repository at this point in the history
* added formatting workflow that fires on push

* Google Java Format

* updated formatting workflow to be able to run on workflow_dispatch

* Clang Format

---------

Co-authored-by: github-actions <>
Co-authored-by: Anka <[email protected]>
  • Loading branch information
MaikuB and Anka authored Sep 28, 2024
1 parent 1b1db82 commit acaef1f
Show file tree
Hide file tree
Showing 19 changed files with 2,732 additions and 1,298 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: format

on:
- push
- workflow_dispatch

jobs:
java_format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: axel-op/googlejavaformat-action@v3
with:
args: '--skip-sorting-imports --replace'

objc_format:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- name: Test
run: |
which clang-format || brew install clang-format
find . -name '*.m' -exec clang-format -i {} \;
find . -path '*/ios/**/*.h' -exec clang-format -i {} \;
find . -path '*/macos/**/*.h' -exec clang-format -i {} \;
git diff --exit-code || (git commit --all -m "Clang Format" && git push)
swift_format:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- name: Test
run: |
which swiftlint || brew install swiftlint
swiftlint --fix
git diff --exit-code || (git commit --all -m "Swift Format" && git push)

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@

public class InsecureConnectionBuilder implements ConnectionBuilder {

public static final InsecureConnectionBuilder INSTANCE = new InsecureConnectionBuilder();
public static final InsecureConnectionBuilder INSTANCE = new InsecureConnectionBuilder();

private InsecureConnectionBuilder() { }
private InsecureConnectionBuilder() {}

@NonNull
@Override
public HttpURLConnection openConnection(@NonNull Uri uri) throws IOException {
return (HttpURLConnection) new URL(uri.toString()).openConnection();
}
@NonNull
@Override
public HttpURLConnection openConnection(@NonNull Uri uri) throws IOException {
return (HttpURLConnection) new URL(uri.toString()).openConnection();
}
}
6 changes: 3 additions & 3 deletions flutter_appauth/ios/Classes/AppAuthIOSAuthorization.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#import <AppAuth/AppAuth.h>
#import <Flutter/Flutter.h>
#import "FlutterAppAuth.h"
#import "OIDExternalUserAgentIOSNoSSO.h"
#import "OIDExternalUserAgentIOSSafariViewController.h"
#import "FlutterAppAuth.h"
#import <AppAuth/AppAuth.h>
#import <Flutter/Flutter.h>

NS_ASSUME_NONNULL_BEGIN

Expand Down
247 changes: 172 additions & 75 deletions flutter_appauth/ios/Classes/AppAuthIOSAuthorization.m

Large diffs are not rendered by default.

44 changes: 34 additions & 10 deletions flutter_appauth/ios/Classes/FlutterAppAuth.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,36 @@ NS_ASSUME_NONNULL_BEGIN

@interface FlutterAppAuth : NSObject

+ (NSMutableDictionary *)processResponses:(OIDTokenResponse*) tokenResponse authResponse:(OIDAuthorizationResponse* _Nullable) authResponse;
+ (void)finishWithError:(NSString *)errorCode message:(NSString *)message result:(FlutterResult)result error:(NSError * _Nullable)error;
+ (NSString *) formatMessageWithError:(NSString *)messageFormat error:(NSError * _Nullable)error;
+ (NSMutableDictionary *)processResponses:(OIDTokenResponse *)tokenResponse
authResponse:(OIDAuthorizationResponse *_Nullable)
authResponse;
+ (void)finishWithError:(NSString *)errorCode
message:(NSString *)message
result:(FlutterResult)result
error:(NSError *_Nullable)error;
+ (NSString *)formatMessageWithError:(NSString *)messageFormat
error:(NSError *_Nullable)error;

@end

static NSString *const AUTHORIZE_METHOD = @"authorize";
static NSString *const AUTHORIZE_AND_EXCHANGE_CODE_METHOD = @"authorizeAndExchangeCode";
static NSString *const AUTHORIZE_AND_EXCHANGE_CODE_METHOD =
@"authorizeAndExchangeCode";
static NSString *const TOKEN_METHOD = @"token";
static NSString *const END_SESSION_METHOD = @"endSession";
static NSString *const AUTHORIZE_ERROR_CODE = @"authorize_failed";
static NSString *const AUTHORIZE_AND_EXCHANGE_CODE_ERROR_CODE = @"authorize_and_exchange_code_failed";
static NSString *const AUTHORIZE_AND_EXCHANGE_CODE_ERROR_CODE =
@"authorize_and_exchange_code_failed";
static NSString *const DISCOVERY_ERROR_CODE = @"discovery_failed";
static NSString *const TOKEN_ERROR_CODE = @"token_failed";
static NSString *const END_SESSION_ERROR_CODE = @"end_session_failed";
static NSString *const DISCOVERY_ERROR_MESSAGE_FORMAT = @"Error retrieving discovery document: %@";
static NSString *const DISCOVERY_ERROR_MESSAGE_FORMAT =
@"Error retrieving discovery document: %@";
static NSString *const TOKEN_ERROR_MESSAGE_FORMAT = @"Failed to get token: %@";
static NSString *const AUTHORIZE_ERROR_MESSAGE_FORMAT = @"Failed to authorize: %@";
static NSString *const END_SESSION_ERROR_MESSAGE_FORMAT = @"Failed to end session: %@";
static NSString *const AUTHORIZE_ERROR_MESSAGE_FORMAT =
@"Failed to authorize: %@";
static NSString *const END_SESSION_ERROR_MESSAGE_FORMAT =
@"Failed to end session: %@";

@interface EndSessionRequestParameters : NSObject
@property(nonatomic, strong) NSString *idTokenHint;
Expand All @@ -50,9 +61,22 @@ typedef NS_ENUM(NSInteger, ExternalUserAgent) {

@interface AppAuthAuthorization : NSObject

- (id<OIDExternalUserAgentSession>)performAuthorization:(OIDServiceConfiguration *)serviceConfiguration clientId:(NSString*)clientId clientSecret:(NSString*)clientSecret scopes:(NSArray *)scopes redirectUrl:(NSString*)redirectUrl additionalParameters:(NSDictionary *)additionalParameters externalUserAgent:(NSNumber*)externalUserAgent result:(FlutterResult)result exchangeCode:(BOOL)exchangeCode nonce:(NSString*)nonce;
- (id<OIDExternalUserAgentSession>)
performAuthorization:(OIDServiceConfiguration *)serviceConfiguration
clientId:(NSString *)clientId
clientSecret:(NSString *)clientSecret
scopes:(NSArray *)scopes
redirectUrl:(NSString *)redirectUrl
additionalParameters:(NSDictionary *)additionalParameters
externalUserAgent:(NSNumber *)externalUserAgent
result:(FlutterResult)result
exchangeCode:(BOOL)exchangeCode
nonce:(NSString *)nonce;

- (id<OIDExternalUserAgentSession>)performEndSessionRequest:(OIDServiceConfiguration *)serviceConfiguration requestParameters:(EndSessionRequestParameters *)requestParameters result:(FlutterResult)result;
- (id<OIDExternalUserAgentSession>)
performEndSessionRequest:(OIDServiceConfiguration *)serviceConfiguration
requestParameters:(EndSessionRequestParameters *)requestParameters
result:(FlutterResult)result;

@end

Expand Down
206 changes: 124 additions & 82 deletions flutter_appauth/ios/Classes/FlutterAppAuth.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,106 +2,148 @@

@implementation FlutterAppAuth

+ (NSMutableDictionary *)processResponses:(OIDTokenResponse*) tokenResponse authResponse:(OIDAuthorizationResponse*) authResponse {
NSMutableDictionary *processedResponses = [[NSMutableDictionary alloc] init];
if(tokenResponse.accessToken) {
[processedResponses setValue:tokenResponse.accessToken forKey:@"accessToken"];
+ (NSMutableDictionary *)processResponses:(OIDTokenResponse *)tokenResponse
authResponse:
(OIDAuthorizationResponse *)authResponse {
NSMutableDictionary *processedResponses = [[NSMutableDictionary alloc] init];
if (tokenResponse.accessToken) {
[processedResponses setValue:tokenResponse.accessToken
forKey:@"accessToken"];
}
if (tokenResponse.accessTokenExpirationDate) {
[processedResponses
setValue:[[NSNumber alloc]
initWithDouble:[tokenResponse.accessTokenExpirationDate
timeIntervalSince1970] *
1000]
forKey:@"accessTokenExpirationTime"];
}
if (authResponse) {
if (authResponse.additionalParameters) {
[processedResponses setObject:authResponse.additionalParameters
forKey:@"authorizationAdditionalParameters"];
}
if(tokenResponse.accessTokenExpirationDate) {
[processedResponses setValue:[[NSNumber alloc] initWithDouble:[tokenResponse.accessTokenExpirationDate timeIntervalSince1970] * 1000] forKey:@"accessTokenExpirationTime"];
if (authResponse.request && authResponse.request.nonce) {
[processedResponses setObject:authResponse.request.nonce forKey:@"nonce"];
}
if(authResponse) {
if (authResponse.additionalParameters) {
[processedResponses setObject:authResponse.additionalParameters forKey:@"authorizationAdditionalParameters"];
}
if (authResponse.request && authResponse.request.nonce) {
[processedResponses setObject:authResponse.request.nonce forKey:@"nonce"];
}
}
if(tokenResponse.additionalParameters) {
[processedResponses setObject:tokenResponse.additionalParameters forKey:@"tokenAdditionalParameters"];
}
if(tokenResponse.idToken) {
[processedResponses setValue:tokenResponse.idToken forKey:@"idToken"];
}
if(tokenResponse.refreshToken) {
[processedResponses setValue:tokenResponse.refreshToken forKey:@"refreshToken"];
}
if (tokenResponse.additionalParameters) {
[processedResponses setObject:tokenResponse.additionalParameters
forKey:@"tokenAdditionalParameters"];
}
if (tokenResponse.idToken) {
[processedResponses setValue:tokenResponse.idToken forKey:@"idToken"];
}
if (tokenResponse.refreshToken) {
[processedResponses setValue:tokenResponse.refreshToken
forKey:@"refreshToken"];
}
if (tokenResponse.tokenType) {
[processedResponses setValue:tokenResponse.tokenType forKey:@"tokenType"];
}
if (tokenResponse.scope) {
[processedResponses
setObject:[tokenResponse.scope componentsSeparatedByString:@" "]
forKey:@"scopes"];
}

return processedResponses;
}

+ (void)finishWithError:(NSString *)errorCode
message:(NSString *)message
result:(FlutterResult)result
error:(NSError *_Nullable)error {

NSMutableDictionary<NSString *, id> *details =
[NSMutableDictionary dictionary];

if (error) {
id authError = error.userInfo[OIDOAuthErrorResponseErrorKey];
NSDictionary<NSString *, id> *authErrorMap =
[authError isKindOfClass:[NSDictionary class]] ? authError : nil;

if (authErrorMap) {
if ([authErrorMap objectForKey:OIDOAuthErrorFieldError]) {
[details setObject:authErrorMap[OIDOAuthErrorFieldError]
forKey:OIDOAuthErrorFieldError];
}
if ([authErrorMap objectForKey:OIDOAuthErrorFieldErrorDescription]) {
[details setObject:authErrorMap[OIDOAuthErrorFieldErrorDescription]
forKey:OIDOAuthErrorFieldErrorDescription];
}
if ([authErrorMap objectForKey:OIDOAuthErrorFieldErrorURI]) {
[details setObject:authErrorMap[OIDOAuthErrorFieldErrorURI]
forKey:OIDOAuthErrorFieldErrorURI];
}
}
if(tokenResponse.tokenType) {
[processedResponses setValue:tokenResponse.tokenType forKey:@"tokenType"];
if (error.domain) {
[details setObject:error.domain forKey:@"type"];
}
if (tokenResponse.scope) {
[processedResponses setObject:[tokenResponse.scope componentsSeparatedByString: @" "] forKey:@"scopes"];
if (error.code) {
[details setObject:[@(error.code) stringValue] forKey:@"code"];
}

return processedResponses;
}

+ (void)finishWithError:(NSString *)errorCode message:(NSString *)message result:(FlutterResult)result error:(NSError * _Nullable)error {

NSMutableDictionary<NSString *, id> *details = [NSMutableDictionary dictionary];

if (error) {
id authError = error.userInfo[OIDOAuthErrorResponseErrorKey];
NSDictionary<NSString *, id> *authErrorMap = [authError isKindOfClass:[NSDictionary class]] ? authError : nil;

if (authErrorMap) {
if ([authErrorMap objectForKey:OIDOAuthErrorFieldError]) {
[details setObject:authErrorMap[OIDOAuthErrorFieldError] forKey:OIDOAuthErrorFieldError];
}
if ([authErrorMap objectForKey:OIDOAuthErrorFieldErrorDescription]) {
[details setObject:authErrorMap[OIDOAuthErrorFieldErrorDescription] forKey:OIDOAuthErrorFieldErrorDescription];
}
if ([authErrorMap objectForKey:OIDOAuthErrorFieldErrorURI]) {
[details setObject:authErrorMap[OIDOAuthErrorFieldErrorURI] forKey:OIDOAuthErrorFieldErrorURI];
}
}
if (error.domain) {
[details setObject:error.domain forKey:@"type"];
}
if (error.code) {
[details setObject:[@(error.code) stringValue] forKey:@"code"];
}

id underlyingErr = [error.userInfo objectForKey:NSUnderlyingErrorKey];
NSError *underlyingError = [underlyingErr isKindOfClass:[NSError class]] ? underlyingErr : nil;
if (underlyingError) {
if (underlyingError.domain) {
[details setObject:underlyingError.domain forKey:@"domain"];
}

if (underlyingError.debugDescription) {
[details setObject:underlyingError.debugDescription forKey:@"root_cause_debug_description"];
}
}

if (error.debugDescription) {
[details setObject:error.debugDescription forKey:@"error_debug_description"];
}

bool userDidCancel = [error.domain isEqual: @"org.openid.appauth.general"]
&& error.code == OIDErrorCodeUserCanceledAuthorizationFlow;
[details setObject:(userDidCancel ? @"true" : @"false") forKey:@"user_did_cancel"];
id underlyingErr = [error.userInfo objectForKey:NSUnderlyingErrorKey];
NSError *underlyingError =
[underlyingErr isKindOfClass:[NSError class]] ? underlyingErr : nil;
if (underlyingError) {
if (underlyingError.domain) {
[details setObject:underlyingError.domain forKey:@"domain"];
}

if (underlyingError.debugDescription) {
[details setObject:underlyingError.debugDescription
forKey:@"root_cause_debug_description"];
}
}
result([FlutterError errorWithCode:errorCode message:message details:details]);

if (error.debugDescription) {
[details setObject:error.debugDescription
forKey:@"error_debug_description"];
}

bool userDidCancel =
[error.domain isEqual:@"org.openid.appauth.general"] &&
error.code == OIDErrorCodeUserCanceledAuthorizationFlow;
[details setObject:(userDidCancel ? @"true" : @"false")
forKey:@"user_did_cancel"];
}
result([FlutterError errorWithCode:errorCode
message:message
details:details]);
}

+ (NSString *) formatMessageWithError:(NSString *)messageFormat error:(NSError * _Nullable)error {
NSString *formattedMessage = [NSString stringWithFormat:messageFormat, [error localizedDescription]];
return formattedMessage;
+ (NSString *)formatMessageWithError:(NSString *)messageFormat
error:(NSError *_Nullable)error {
NSString *formattedMessage =
[NSString stringWithFormat:messageFormat, [error localizedDescription]];
return formattedMessage;
}

@end

@implementation AppAuthAuthorization

- (id<OIDExternalUserAgentSession>)performAuthorization:(OIDServiceConfiguration *)serviceConfiguration clientId:(NSString*)clientId clientSecret:(NSString*)clientSecret scopes:(NSArray *)scopes redirectUrl:(NSString*)redirectUrl additionalParameters:(NSDictionary *)additionalParameters externalUserAgent:(NSNumber*)externalUserAgent result:(FlutterResult)result exchangeCode:(BOOL)exchangeCode nonce:(NSString*)nonce {
return nil;
- (id<OIDExternalUserAgentSession>)
performAuthorization:(OIDServiceConfiguration *)serviceConfiguration
clientId:(NSString *)clientId
clientSecret:(NSString *)clientSecret
scopes:(NSArray *)scopes
redirectUrl:(NSString *)redirectUrl
additionalParameters:(NSDictionary *)additionalParameters
externalUserAgent:(NSNumber *)externalUserAgent
result:(FlutterResult)result
exchangeCode:(BOOL)exchangeCode
nonce:(NSString *)nonce {
return nil;
}

- (id<OIDExternalUserAgentSession>)performEndSessionRequest:(OIDServiceConfiguration *)serviceConfiguration requestParameters:(EndSessionRequestParameters *)requestParameters result:(FlutterResult)result {
return nil;
- (id<OIDExternalUserAgentSession>)
performEndSessionRequest:(OIDServiceConfiguration *)serviceConfiguration
requestParameters:(EndSessionRequestParameters *)requestParameters
result:(FlutterResult)result {
return nil;
}

@end
9 changes: 5 additions & 4 deletions flutter_appauth/ios/Classes/FlutterAppauthPlugin.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
#import <TargetConditionals.h>

#if TARGET_OS_OSX
#import <FlutterMacOS/FlutterMacOS.h>
#import "AppAuthMacOSAuthorization.h"
#import <FlutterMacOS/FlutterMacOS.h>
#else
#import <Flutter/Flutter.h>
#import "AppAuthIOSAuthorization.h"
#import <Flutter/Flutter.h>
#endif

#import <AppAuth/AppAuth.h>

@interface FlutterAppauthPlugin : NSObject<FlutterPlugin>
@interface FlutterAppauthPlugin : NSObject <FlutterPlugin>

@property(nonatomic, strong, nullable) id<OIDExternalUserAgentSession> currentAuthorizationFlow;
@property(nonatomic, strong, nullable) id<OIDExternalUserAgentSession>
currentAuthorizationFlow;

@end
Loading

0 comments on commit acaef1f

Please sign in to comment.