Skip to content

Commit

Permalink
feat(code): #13: authorizationCodeOnly from master
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Oberwasserlechner committed Feb 8, 2019
1 parent 27f8e84 commit 7166c26
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public class OAuth2ClientPlugin extends Plugin {
private static final String PARAM_RESOURCE_URL = "resourceUrl";
private static final String RESPONSE_TYPE_CODE = "code";
private static final String RESPONSE_TYPE_TOKEN = "token";
// private static final String PARAM_AUTHORIZATION_CODE_ONLY = "authorizationCodeOnly";

private OAuth2Options oauth2Options;
private AuthorizationService authService;
Expand Down Expand Up @@ -193,13 +192,6 @@ protected OAuth2Options buildOptions(PluginCall call) {
if (o.getState() == null || o.getState().trim().length() == 0) {
o.setState(ConfigUtils.getRandomString(20));
}
// o.setAuthorizationCodeOnly(ConfigUtils.getCallParam(Boolean.class, call, OAuth2ClientPlugin.PARAM_AUTHORIZATION_CODE_ONLY, false));
// if (o.isAuthorizationCodeOnly()) {
// if (!RESPONSE_TYPE_CODE.equals(o.getResponseType())) {
// Log.w(getLogTag(), "'" + PARAM_AUTHORIZATION_CODE_ONLY + "' is 'true' so '" + PARAM_RESPONSE_TYPE + "' must be 'code'! We fix that for you.");
// }
// o.setResponseType(RESPONSE_TYPE_CODE);
// }

if (o.getResponseType() == null || o.getResponseType().length() == 0) {
// fallback to token
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public class OAuth2Options {
private String responseType;
private String scope;
private String state;
// private boolean authorizationCodeOnly;
private String redirectUrl;
private String customHandlerClass;

Expand Down Expand Up @@ -72,14 +71,6 @@ public void setState(String state) {
this.state = state;
}

// public boolean isAuthorizationCodeOnly() {
// return authorizationCodeOnly;
// }
//
// public void setAuthorizationCodeOnly(boolean authorizationCodeOnly) {
// this.authorizationCodeOnly = authorizationCodeOnly;
// }

public String getRedirectUrl() {
return redirectUrl;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public class OAuth2ClientPlugin: CAPPlugin {
let PARAM_RESOURCE_URL = "resourceUrl"
let RESPONSE_TYPE_CODE = "code"
let RESPONSE_TYPE_TOKEN = "token"
// let PARAM_AUTHORIZATION_CODE_ONLY = "authorizationCodeOnly"

var oauthSwift: OAuth2Swift?
var handlerClasses = [String: OAuth2CustomHandler.Type]()
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@byteowls/capacitor-oauth2",
"version": "1.0.0-alpha.28",
"version": "1.0.0-beta.1",
"description": "Simple Capacitor OAuth 2 client plugin",
"author": "Michael Oberwasserlechner",
"homepage": "https://github.com/moberwasserlechner/capacitor-oauth2",
Expand Down
11 changes: 2 additions & 9 deletions src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ export interface OAuth2AuthenticateOptions {
*/
resourceUrl?: string;
/**
* Defaults to 'token' aka implicit flow if emtpy and not used with @authorizationCodeOnly.
* Defaults to 'token' aka implicit flow if emtpy.
*
* Be aware that this plugin does not support code flow with client secrets because of security reason.
* Be aware that this plugin does not support authorization code flow with client secrets because of security reason.
*
* However code + PKCE will be supported in future. Please see github issue #4
*/
Expand All @@ -55,13 +55,6 @@ export interface OAuth2AuthenticateOptions {
* and sends it as using state is recommended.
*/
state?: string;

// /**
// * Force the lib to only return the authorization code in the result.
// * If true we use the code flow and the requestType is always "code".
// * This becomes handy if you want to use it as part of a server side authorization code flow.
// */
// authorizationCodeOnly?: boolean;
/**
* Custom options for the platform "web"
*/
Expand Down
7 changes: 0 additions & 7 deletions src/web-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@ export class WebUtils {
let appId = this.getAppId(options);
let url = options.authorizationBaseUrl + "?client_id=" + appId;

if (options.authorizationCodeOnly) {
if (options.responseType !== "code") {
console.warn("'authorizationCodeOnly' is 'true' so 'responseType' must be 'code'! We fix that for you.");
}
options.responseType = "code";
}

if (!options.responseType) {
options.responseType = "token";
}
Expand Down
9 changes: 1 addition & 8 deletions src/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,7 @@ export class OAuth2ClientPluginWeb extends WebPlugin implements OAuth2ClientPlug
// code flow
let authorizationCode = urlParamObj.code;
if (authorizationCode) {
// if (options.authorizationCodeOnly) {
// let resp = {
// authorization_code: authorizationCode,
// };
// resolve(resp);
// } else {
// // TODO PKCE
// }
// TODO PKCE
} else {
reject(new Error("No authorization code found!"));
}
Expand Down

0 comments on commit 7166c26

Please sign in to comment.