Skip to content

Commit

Permalink
Merge branch 'master' into keycloak21.x.x
Browse files Browse the repository at this point in the history
  • Loading branch information
cooperlyt committed Apr 6, 2023
2 parents bb162ba + 4047f34 commit 518e2a6
Show file tree
Hide file tree
Showing 16 changed files with 160 additions and 21 deletions.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ This is what you can do for now:

## Features

### New in Version 2.3.3
+ Add `Condition - phone provided` [#46](https://github.com/cooperlyt/keycloak-phone-provider/issues/46)

### New in Version 2.3.2
+ fix phone login form display error!

Expand Down Expand Up @@ -72,7 +75,7 @@ anymore and I did not test user storage beyond Kerberos or LDAP. I may try to he
### **Installing:**

+ Docker
1. docker image is [coopersoft/keycloak:21.0.2_phone-2.3.2](https://hub.docker.com/repository/docker/coopersoft/keycloak)
1. docker image is [coopersoft/keycloak:21.0.2_phone-2.3.3](https://hub.docker.com/repository/docker/coopersoft/keycloak)
2. for examples [docker-compose.yml](https://raw.githubusercontent.com/cooper-lyt/keycloak-phone-provider/master/examples/docker-compose.yml)
3. run as `docker-compose up` , [docker-compose](https://docs.docker.com/compose/) is required!

Expand Down Expand Up @@ -219,6 +222,10 @@ Bind `Direct Grant Flow` to `Direct grant with phone`

![Setting](https://github.com/cooper-lyt/keycloak-phone-provider/raw/master/examples/document/c0.jpg)

Either Phone/Otp or Username/Password :
![Setting](https://github.com/cooper-lyt/keycloak-phone-provider/raw/master/examples/document/f0.png)


### **Everybody phone number( if not exists create user by phone number) get Access token use endpoints:**

Under `Authentication` > `Flows`:
Expand Down Expand Up @@ -261,11 +268,15 @@ Set Bind `Reset credentials with phone` to `Reset credentials flow`

![Authentication setting](https://github.com/cooper-lyt/keycloak-phone-provider/raw/master/examples/document/d0.jpg)

## **Conditional**
`Condition - phone provided`

## **Required Action**
+ `Update Phone Number` update user's phone number on next login.
+ `Configure OTP over SMS` update OTP Credential's phone number on next login.



**Phone one key login**
Testing , coming soon!

Expand Down
Binary file added examples/document/f0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion keycloak-phone-provider.resources/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>cc.coopersoft</groupId>
<artifactId>keycloak-phone-provider-parent</artifactId>
<version>2.3.2</version>
<version>2.3.3</version>
</parent>

<artifactId>keycloak-phone-provider.resources</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion keycloak-phone-provider/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>cc.coopersoft</groupId>
<artifactId>keycloak-phone-provider-parent</artifactId>
<version>2.3.2</version>
<version>2.3.3</version>
</parent>

<artifactId>keycloak-phone-provider</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package cc.coopersoft.keycloak.phone.authentication.authenticators.conditional;

import cc.coopersoft.common.OptionalUtils;
import org.keycloak.authentication.AuthenticationFlowContext;
import org.keycloak.authentication.authenticators.conditional.ConditionalAuthenticator;
import org.keycloak.authentication.authenticators.conditional.ConditionalUserAttributeValueFactory;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.RealmModel;
import org.keycloak.models.UserModel;

public class ConditionalPhoneProvided implements ConditionalAuthenticator {

static final ConditionalPhoneProvided SINGLETON = new ConditionalPhoneProvided();

@Override
public boolean matchCondition(AuthenticationFlowContext context) {
var config = context.getAuthenticatorConfig().getConfig();
boolean negateOutput = Boolean.parseBoolean(config.get(ConditionalUserAttributeValueFactory.CONF_NOT));

boolean result = OptionalUtils.ofBlank(OptionalUtils.ofBlank(
context.getHttpRequest().getDecodedFormParameters().getFirst("phone_number"))
.orElse(context.getHttpRequest().getDecodedFormParameters().getFirst("phoneNumber"))).isPresent();
return negateOutput != result;
}

@Override
public void action(AuthenticationFlowContext authenticationFlowContext) {
// Not used
}

@Override
public boolean requiresUser() {
return false;
}

@Override
public void setRequiredActions(KeycloakSession keycloakSession, RealmModel realmModel, UserModel userModel) {
// Not used
}

@Override
public void close() {
// Does nothing
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package cc.coopersoft.keycloak.phone.authentication.authenticators.conditional;

import org.keycloak.Config;
import org.keycloak.authentication.authenticators.conditional.ConditionalAuthenticator;
import org.keycloak.authentication.authenticators.conditional.ConditionalAuthenticatorFactory;
import org.keycloak.models.AuthenticationExecutionModel;
import org.keycloak.models.KeycloakSessionFactory;
import org.keycloak.provider.ProviderConfigProperty;

import java.util.Collections;
import java.util.List;

public class ConditionalPhoneProvidedFactory implements ConditionalAuthenticatorFactory {

public static final String PROVIDER_ID = "conditional-phone-provided";
public static final String CONF_NOT = "not";

private static final AuthenticationExecutionModel.Requirement[] REQUIREMENT_CHOICES = {
AuthenticationExecutionModel.Requirement.REQUIRED, AuthenticationExecutionModel.Requirement.DISABLED
};

@Override
public ConditionalAuthenticator getSingleton() {
return ConditionalPhoneProvided.SINGLETON;
}

@Override
public String getDisplayType() {
return "Condition - phone provided";
}

@Override
public boolean isConfigurable() {
return true;
}

@Override
public AuthenticationExecutionModel.Requirement[] getRequirementChoices() {
return REQUIREMENT_CHOICES;
}

@Override
public boolean isUserSetupAllowed() {
return false;
}

@Override
public String getHelpText() {
return "Flow is executed only if the phone number provided";
}

@Override
public List<ProviderConfigProperty> getConfigProperties() {
ProviderConfigProperty negateOutput = new ProviderConfigProperty();
negateOutput.setType(ProviderConfigProperty.BOOLEAN_TYPE);
negateOutput.setName(CONF_NOT);
negateOutput.setLabel("Negate output");
negateOutput.setHelpText("Apply a not to the check result");

return Collections.singletonList(negateOutput);
}

@Override
public void init(Config.Scope scope) {

}

@Override
public void postInit(KeycloakSessionFactory keycloakSessionFactory) {

}

@Override
public void close() {

}

@Override
public String getId() {
return PROVIDER_ID;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ cc.coopersoft.keycloak.phone.authentication.authenticators.resetcred.ResetCreden
cc.coopersoft.keycloak.phone.authentication.authenticators.resetcred.ResetCredentialEmailWithPhone
cc.coopersoft.keycloak.phone.authentication.authenticators.directgrant.AuthenticationCodeAuthenticatorFactory
cc.coopersoft.keycloak.phone.authentication.authenticators.directgrant.PhoneNumberAuthenticatorFactory
cc.coopersoft.keycloak.phone.authentication.authenticators.directgrant.EverybodyPhoneAuthenticatorFactory
cc.coopersoft.keycloak.phone.authentication.authenticators.directgrant.EverybodyPhoneAuthenticatorFactory
cc.coopersoft.keycloak.phone.authentication.authenticators.conditional.ConditionalPhoneProvidedFactory
4 changes: 2 additions & 2 deletions keycloak-sms-provider-aliyun/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>keycloak-phone-provider-parent</artifactId>
<groupId>cc.coopersoft</groupId>
<version>2.3.2</version>
<version>2.3.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -16,7 +16,7 @@
<dependency>
<groupId>cc.coopersoft</groupId>
<artifactId>keycloak-phone-provider</artifactId>
<version>2.3.2</version>
<version>2.3.3</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
4 changes: 2 additions & 2 deletions keycloak-sms-provider-aws-sns/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>cc.coopersoft</groupId>
<artifactId>keycloak-phone-provider-parent</artifactId>
<version>2.3.2</version>
<version>2.3.3</version>
</parent>

<artifactId>keycloak-sms-provider-aws-sns</artifactId>
Expand All @@ -16,7 +16,7 @@
<dependency>
<groupId>cc.coopersoft</groupId>
<artifactId>keycloak-phone-provider</artifactId>
<version>2.3.2</version>
<version>2.3.3</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
4 changes: 2 additions & 2 deletions keycloak-sms-provider-cloopen/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>cc.coopersoft</groupId>
<artifactId>keycloak-phone-provider-parent</artifactId>
<version>2.3.2</version>
<version>2.3.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -15,7 +15,7 @@
<dependency>
<groupId>cc.coopersoft</groupId>
<artifactId>keycloak-phone-provider</artifactId>
<version>2.3.2</version>
<version>2.3.3</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
4 changes: 2 additions & 2 deletions keycloak-sms-provider-dummy/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>cc.coopersoft</groupId>
<artifactId>keycloak-phone-provider-parent</artifactId>
<version>2.3.2</version>
<version>2.3.3</version>
</parent>

<artifactId>keycloak-sms-provider-dummy</artifactId>
Expand All @@ -16,7 +16,7 @@
<dependency>
<groupId>cc.coopersoft</groupId>
<artifactId>keycloak-phone-provider</artifactId>
<version>2.3.2</version>
<version>2.3.3</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down
4 changes: 2 additions & 2 deletions keycloak-sms-provider-tencent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>keycloak-phone-provider-parent</artifactId>
<groupId>cc.coopersoft</groupId>
<version>2.3.2</version>
<version>2.3.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -16,7 +16,7 @@
<dependency>
<groupId>cc.coopersoft</groupId>
<artifactId>keycloak-phone-provider</artifactId>
<version>2.3.2</version>
<version>2.3.3</version>
<scope>provided</scope>
</dependency>

Expand Down
4 changes: 2 additions & 2 deletions keycloak-sms-provider-totalvoice/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>cc.coopersoft</groupId>
<artifactId>keycloak-phone-provider-parent</artifactId>
<version>2.3.2</version>
<version>2.3.3</version>
</parent>

<artifactId>keycloak-sms-provider-totalvoice</artifactId>
Expand All @@ -16,7 +16,7 @@
<dependency>
<groupId>cc.coopersoft</groupId>
<artifactId>keycloak-phone-provider</artifactId>
<version>2.3.2</version>
<version>2.3.3</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
4 changes: 2 additions & 2 deletions keycloak-sms-provider-twilio/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>cc.coopersoft</groupId>
<artifactId>keycloak-phone-provider-parent</artifactId>
<version>2.3.2</version>
<version>2.3.3</version>
</parent>

<artifactId>keycloak-sms-provider-twilio</artifactId>
Expand All @@ -16,7 +16,7 @@
<dependency>
<groupId>cc.coopersoft</groupId>
<artifactId>keycloak-phone-provider</artifactId>
<version>2.3.2</version>
<version>2.3.3</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
4 changes: 2 additions & 2 deletions keycloak-sms-provider-yunxin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>keycloak-phone-provider-parent</artifactId>
<groupId>cc.coopersoft</groupId>
<version>2.3.2</version>
<version>2.3.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -15,7 +15,7 @@
<dependency>
<groupId>cc.coopersoft</groupId>
<artifactId>keycloak-phone-provider</artifactId>
<version>2.3.2</version>
<version>2.3.3</version>
<scope>provided</scope>
</dependency>

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>cc.coopersoft</groupId>
<artifactId>keycloak-phone-provider-parent</artifactId>
<packaging>pom</packaging>
<version>2.3.2</version>
<version>2.3.3</version>

<name>keycloak-phone-provider</name>
<description>keycloak phone support.</description>
Expand Down

0 comments on commit 518e2a6

Please sign in to comment.