Thursday, December 5, 2019

How can we test google oauth2 using curl?

Answer is available in this link with full description:

https://github.com/jhanley-com/google-oauth-2-0-testing-with-curl

What is Access Token, ID Token? How can we retreive User info from Access Token or ID Token?

What is an Access Token?
An Access token is a Bearer token that you will have to add in all request headers to be authenticated as a concrete user.

Resource Link: https://stackoverflow.com/questions/25838183/what-is-the-oauth-2-0-bearer-token-exactly/25843058

What is an ID Token?


An ID Token is a JWT (JSON Web Token), that is, a cryptographically signed Base64-encoded JSON object. Normally, it is critical that you validate an ID token before you use it, but since you are communicating directly with Google over an intermediary-free HTTPS channel and using your client secret to authenticate yourself to Google, you can be confident that the token you receive really comes from Google and is valid. If your server passes the ID token to other components of your app, it is extremely important that the other components validate the token before using it.

Since most API libraries combine the validation with the work of decoding the base64 and parsing the JSON, you will probably end up validating the token anyway as you access the fields in the ID token.

An ID token's payload
An ID token is a JSON object containing a set of name/value pairs. Here’s an example, formatted for readability:

{
  "iss": "accounts.google.com",
  "at_hash": "HK6E_P6Dh8Y93mRNtsDB1Q",
  "email_verified": "true",
  "sub": "10769150350006150715113082367",
  "azp": "1234987819200.apps.googleusercontent.com",
  "email": "jsmith@example.com",
  "aud": "1234987819200.apps.googleusercontent.com",
  "iat": 1353601026,
  "exp": 1353604926,
  "nonce": "0394852-3190485-2490358",
  "hd": "example.com"
}

Resource Link: https://developers.google.com/identity/protocols/OpenIDConnect#obtainuserinfo

How can we retreive User info from Access Token or ID Token?

Answer is available in this link: https://www.oauth.com/oauth2-servers/signing-in-with-google/verifying-the-user-info/

Resource Link:

  1. https://stackoverflow.com/questions/16501895/how-do-i-get-user-profile-using-google-access-token
  2. https://stackoverflow.com/questions/22516693/how-to-get-user-profile-on-google-api-using-the-java-library

Saturday, November 9, 2019

Microsoft SQL Server Installation and Configuration Step by Step

  1. Microsoft SQL Server 2017 Installation - Step By Step Process To Install SQL Server: https://www.youtube.com/watch?v=yasfZuou3zI
  2. How to Create MS SQL Database Using SQL Server Management Studio - For Beginners: https://www.youtube.com/watch?v=zqo2ZBxxn6M
  3. Getting Exception:
    The TCP/IP connection to the host localhost, port 1433 has failed error, need assistance

    Solution: https://stackoverflow.com/questions/33590030/the-tcp-ip-connection-to-the-host-localhost-port-1433-has-failed-error-need-as
  4. how to restart the sql server in windows?
    https://www.isunshare.com/sql-server/how-to-operate-sql-server-service.html

Thursday, October 17, 2019

Builder Design Pattern

Java Builder Pattern:

1. Primary Builder Pattern Example:
--------------------------------
https://github.com/davidmoten/java-builder

2. Java Builder Pattern tricks - you must know:
--------------------------------------------
https://github.com/davidmoten/java-builder-pattern-tricks


Pattern Builder:
----------------
Builder pattern is a creational design pattern as Factory Pattern and Abstract Factory Pattern. This pattern was introduced to solve some of the problems with Factory and Abstract Factory patterns when the Object contains a lot of attributes. This pattern deals with a static nested class and then copy all the arguments from the outer class to the Builder class. The sample code where we have a Computer class and ComputerBuilder to build it are available in the package com.builder.Computer. Here's a test program showing how to use Builder class to get object.

import com.builder.Computer;

public class TestBuilderPattenr{
  public static void main(String[] args){

      Computer comp = new Computer.ComputerBuilder(
      "500 GB","2 GB").setBluetoothEnabled(true)
      .setGraphicsCardEnabled(true).build(); // -)
      )
  }

}
There are really various implementations of this pattern in JDK : java.lang.StringBuilder#append() (unsynchronized) java.lang.StringBuffer#append() (synchronized) .

Resource Link: https://github.com/sdmg15/Java-design-patterns

https://github.com/sanketgupta07/DesignPattern/tree/master/src/pattern

Monday, September 9, 2019

Deploy spring boot web application in Azure as App Service

Deploy spring boot web application in Azure as App Service


  1. https://www.youtube.com/watch?v=7gJVMzfjHpQ

Spring Boot WAR file is not working after tomcat deployment in Microsoft azure:

Jar is working fine. But if I create war file, then it is not working.

For Maven Users:
================


for creating war file, I need to change the following.

1. In pom.xml file, add [packaging] tag file.
<packaging>war</packaging>

2. Add start-class in properties section of pom.xml file
<properties>     
    <start-class>mypackage.App</start-class>
</properties>

3. Main Application class should look like below:
@SpringBootApplication
public class Application extends SpringBootServletInitializer {

    /**
     * Used when run as JAR
     */
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
    /**
     * Used when run as WAR
     */
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(Application.class);
    }
}
Resource Link:


  1. https://stackoverflow.com/a/39445027


For Gradle Users:


1. Add plugin to build.gradle

apply plugin: 'war'

2. Add provided dependency to tomcat

dependencies {
    // other dependencies
    providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
}